提问人:sk2212 提问时间:2/9/2022 更新时间:2/9/2022 访问量:553
Android NDK GNU Ld 找不到符号,但 LLD 9.0.9 可以找到
Android NDK GNU Ld does not find symbols but LLD 9.0.9 does
问:
我正在使用 NDK21 工具链编译第三方库 (libstrophe)。对于 Android 64 位目标,如果使用 GNU 链接器,它将失败并出现以下错误:
$ /opt/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang -I. -I/home/sandro/Projects/libstrophe_ref/openssl/include -I/home/sandro/Projects/libstrophe_ref/libxml2/include -Werror -g -o examples/.libs/active examples/examples_active-active.o -L../openssl/android_aarch64_ndk21 -L../libxml2/android_aarch64_ndk21 ./.libs/libstrophe.so -L/home/sandro/Projects/libstrophe_ref/temp_build/lib -v
Android (7019983 based on r365631c3) clang version 9.0.9 (https://android.googlesource.com/toolchain/llvm-project a2a1e703c0edb03ba29944e529ccbf457742737b) (based on LLVM 9.0.9svn)
Target: aarch64-unknown-linux-android21
Thread model: posix
InstalledDir: /opt/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin
Found candidate GCC installation: /opt/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x
Selected GCC installation: /opt/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x
Candidate multilib: .;@m64
Selected multilib: .;@m64
"/opt/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld" -pie -z noexecstack -EL --fix-cortex-a53-843419 --warn-shared-textrel -z now -z relro -z max-page-size=4096 --hash-style=gnu --hash-style=both --enable-new-dtags --eh-frame-hdr -m aarch64linux -dynamic-linker /system/bin/linker64 -o examples/.libs/active /opt/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/21/crtbegin_dynamic.o -L../openssl/android_aarch64_ndk21 -L../libxml2/android_aarch64_ndk21 -L/home/sandro/Projects/libstrophe_ref/temp_build/lib -L/opt/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.9/lib/linux/aarch64 -L/opt/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x -L/opt/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/lib/../lib64 -L/opt/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/21 -L/opt/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android -L/opt/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/lib -L/opt/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib examples/examples_active-active.o ./.libs/libstrophe.so -lgcc -ldl -lc -lgcc -ldl /opt/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/21/crtend_android.o
/opt/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: warning: libssl_1_1.so, needed by ./.libs/libstrophe.so, not found (try using -rpath or -rpath-link)
/opt/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: warning: libcrypto_1_1.so, needed by ./.libs/libstrophe.so, not found (try using -rpath or -rpath-link)
/opt/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: warning: libxml2.so, needed by ./.libs/libstrophe.so, not found (try using -rpath or -rpath-link)
./.libs/libstrophe.so: undefined reference to `OPENSSL_init_ssl@OPENSSL_1_1_0'
./.libs/libstrophe.so: undefined reference to `xmlParseChunk@LIBXML2_2.4.30'
./.libs/libstrophe.so: undefined reference to `SSL_write@OPENSSL_1_1_0'
./.libs/libstrophe.so: undefined reference to `SSL_CTX_ctrl@OPENSSL_1_1_0'
./.libs/libstrophe.so: undefined reference to `xmlCreatePushParserCtxt@LIBXML2_2.4.30'
./.libs/libstrophe.so: undefined reference to `SSL_pending@OPENSSL_1_1_0'
./.libs/libstrophe.so: undefined reference to `SSL_read@OPENSSL_1_1_0'
./.libs/libstrophe.so: undefined reference to `SSL_free@OPENSSL_1_1_0'
./.libs/libstrophe.so: undefined reference to `xmlFreeParserCtxt@LIBXML2_2.4.30'
./.libs/libstrophe.so: undefined reference to `SSL_get_error@OPENSSL_1_1_0'
./.libs/libstrophe.so: undefined reference to `SSL_set_fd@OPENSSL_1_1_0'
./.libs/libstrophe.so: undefined reference to `SSL_shutdown@OPENSSL_1_1_0'
./.libs/libstrophe.so: undefined reference to `SSL_connect@OPENSSL_1_1_0'
./.libs/libstrophe.so: undefined reference to `SSL_CTX_set_verify@OPENSSL_1_1_0'
./.libs/libstrophe.so: undefined reference to `SSL_CTX_free@OPENSSL_1_1_0'
./.libs/libstrophe.so: undefined reference to `SSL_new@OPENSSL_1_1_0'
./.libs/libstrophe.so: undefined reference to `TLS_client_method@OPENSSL_1_1_0'
./.libs/libstrophe.so: undefined reference to `SSL_CTX_set_client_cert_cb@OPENSSL_1_1_0'
./.libs/libstrophe.so: undefined reference to `SSL_CTX_new@OPENSSL_1_1_0'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
如果我强制使用 clang LLD,它工作正常 ():-fuse-ld=lld
$ /opt/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang
-I. -I/home/sandro/Projects/libstrophe_ref/openssl/include -I/home/sandro/Projects/libstrophe_ref/libxml2/include -Werror -g -o examples/.libs/active examples/examples_active-active.o
-L../openssl/android_aarch64_ndk21 -L../libxml2/android_aarch64_ndk21 ./.libs/libstrophe.so
-L/home/sandro/Projects/libstrophe_ref/temp_build/lib -fuse-ld=lld -v Android (7019983 based on r365631c3) clang version 9.0.9 (https://android.googlesource.com/toolchain/llvm-project a2a1e703c0edb03ba29944e529ccbf457742737b) (based on LLVM 9.0.9svn) Target: aarch64-unknown-linux-android21 Thread model: posix InstalledDir: /opt/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin Found candidate GCC installation: /opt/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x Selected GCC installation: /opt/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x Candidate multilib: .;@m64 Selected multilib: .;@m64 "/opt/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/ld.lld"
-pie -z noexecstack -EL --fix-cortex-a53-843419 --warn-shared-textrel -z now -z relro -z max-page-size=4096 --hash-style=gnu --hash-style=both --enable-new-dtags --eh-frame-hdr -m aarch64linux -dynamic-linker /system/bin/linker64 -o examples/.libs/active /opt/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/21/crtbegin_dynamic.o -L../openssl/android_aarch64_ndk21 -L../libxml2/android_aarch64_ndk21 -L/home/sandro/Projects/libstrophe_ref/temp_build/lib -L/opt/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.9/lib/linux/aarch64
-L/opt/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x
-L/opt/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/lib/../lib64
-L/opt/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/21
-L/opt/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android
-L/opt/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/lib
-L/opt/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib examples/examples_active-active.o ./.libs/libstrophe.so -lgcc -ldl -lc
-lgcc -ldl /opt/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/21/crtend_android.o
问题
GNU Linker 没有找到对象引用,而 LDD Clang Linker 找到的原因是什么?
如果我为 Android 32 位目标编译,它也适用于 GNU 链接器。
答: 暂无答案
评论