编译arm64-v8a时libcrypto.a报错,需要添加-fPIC编译选项

  • Creator 版本: cocos creator 2.4.3

  • 目标平台: google浏览器 / Android/ 小游戏真机

  • 重现方式:指定 arm64-v8a 编译签名包时,必现

  • 首个报错: ld: error: relocation R_AARCH64_PREL64 cannot be used against symbol OPENSSL_armcap_P; recompile with -fPIC

    defined in D:/CocosDashboard_1.0.11/resources/.editors/Creator/2.4.3/resources/cocos2d-x/external/android/arm64-v8a/libcrypto.a(armcap.o)
    referenced by chacha-armv8.o:(.text+0x20) in archive D:/CocosDashboard_1.0.11/resources/.editors/Creator/2.4.3/resources/cocos2d-x/external/android/arm64-v8a/libcrypto.a

    ld: error: relocation R_AARCH64_PREL64 cannot be used against symbol OPENSSL_armcap_P; recompile with -fPIC

    defined in D:/CocosDashboard_1.0.11/resources/.editors/Creator/2.4.3/resources/cocos2d-x/external/android/arm64-v8a/libcrypto.a(armcap.o)
    referenced by poly1305-armv8.o:(.text+0x9A0) in archive D:/CocosDashboard_1.0.11/resources/.editors/Creator/2.4.3/resources/cocos2d-x/external/android/arm64-v8a/libcrypto.a

    ld: error: relocation R_AARCH64_PREL64 cannot be used against symbol OPENSSL_armcap_P; recompile with -fPIC

    defined in D:/CocosDashboard_1.0.11/resources/.editors/Creator/2.4.3/resources/cocos2d-x/external/android/arm64-v8a/libcrypto.a(armcap.o)
    referenced by sha1-armv8.o:(.text+0x1240) in archive D:/CocosDashboard_1.0.11/resources/.editors/Creator/2.4.3/resources/cocos2d-x/external/android/arm64-v8a/libcrypto.a

    ld: error: relocation R_AARCH64_PREL64 cannot be used against symbol OPENSSL_armcap_P; recompile with -fPIC

    defined in D:/CocosDashboard_1.0.11/resources/.editors/Creator/2.4.3/resources/cocos2d-x/external/android/arm64-v8a/libcrypto.a(armcap.o)
    referenced by sha256-armv8.o:(.text+0xF48) in archive D:/CocosDashboard_1.0.11/resources/.editors/Creator/2.4.3/resources/cocos2d-x/external/android/arm64-v8a/libcrypto.a

    ld: error: relocation R_AARCH64_PREL64 cannot be used against symbol OPENSSL_armcap_P; recompile with -fPIC

    defined in D:/CocosDashboard_1.0.11/resources/.editors/Creator/2.4.3/resources/cocos2d-x/external/android/arm64-v8a/libcrypto.a(armcap.o)
    referenced by sha512-armv8.o:(.text+0x10C8) in archive D:/CocosDashboard_1.0.11/resources/.editors/Creator/2.4.3/resources/cocos2d-x/external/android/arm64-v8a/libcrypto.a
    clang++: error: linker command failed with exit code 1 (use -v to see invocation)
    make: *** [D:/Android/sdk/ndk/22.0.7026061/build//…/build/core/build-binary.mk:728: E:/WordCross/WordCross/build/jsb-link/frameworks/runtime-src/proj.android-studio/app/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/libcocos2djs.so] Error 1

  • 之前哪个版本是正常的:

  • 手机型号:

  • 手机浏览器:

  • 编辑器操作系统:

  • 重现概率:

做下补充说明
1、构建发布的签名包时,报 libcrypto.a 错误
2、环境修改:
官方对 gradle 的版本支持有说明,但 google play 也有明确说明,要使用新商店或特性要升级 gradle 版本,结果是我升级了我的配置如下
image

3、编译选项添加 arm64-v8a,在编译完成链接阶段出现报错如下

其实信息已经比较明显了,在使用 libcrypto动态库时遇到问题,建议在编译选项中加入 -fPIC 重新编译。但是,我尝试了多个地方添加此标记都没成功。

虽然我已经通过自己的方法解决了此问题,但本着遇到问题就要搞明白的心态,抛下这个问题,1是看下有没有遇到同样问题的,2是你们是怎样解决的。我是搞定了支持 arm64 的库后替换掉 libcrypto.a、libssl.a、libwebsockets.a搞定的

这是迂回的方式,问下大家有没有直接修改原环境搞定的???具体是在哪里添加的这个编译选项

又仔细看了下 cocos creator 下边自带的 cocos2dx 目录下的内容,基本可以确定没有外部库有源码,只有编译好的库文件。所以可以确定想通过增加 -fPIC 来解决此问题是不可能的

只能想办法找到这几个库的源码然后自己在编译选项中添加这个标记,然后象我上面那样覆盖掉有问题的库(记得先备份)

不知道官方的 cocos2dx 对应版本里有没有源码,有空看一下

https://github.com/cocos-creator/engine-native-external 把最新分支拉下来 有问题的库替换一下试试

这种方法就和我上边自己搞定后替换库文件一样了,替换掉上边的三个文件就 ok 了,谢谢回复