【发布时间】:2017-11-05 06:34:12
【问题描述】:
我构建了 libssl.a 和 libcryto.a。但是当我想将 my.so 链接到它时,我得到了这个错误:
Error:(130) undefined reference to 'BIO_new_dgram'
如果我删除这个调用,我可以编译成功。
我是否以错误的方式构建 openssl 库?
BIO_new_dgram 在 libcrypto.a 中:
nm libcrypto.a | grep BIO_new_dgram
0000081c T BIO_new_dgram
我用以下方式配置 Openssl:
./config shared --openssldir=$install_dir --prefix=$install_dir
和链接命令:
/home/choury/bin/Android/android-sdk-linux/ndk-bundle/toolchains/llvm/prebuilt/l
inux-x86_64/bin/clang++ --target=aarch64-none-linux-android --gcc-toolchain=/ho
me/choury/bin/Android/android-sdk-linux/ndk-bundle/toolchains/aarch64-linux-andr
oid-4.9/prebuilt/linux-x86_64 --sysroot=/home/choury/bin/Android/android-sdk-lin
ux/ndk-bundle/platforms/android-21/arch-arm64 -fPIC -std=c++11 -Wall -fPIC -ggdb
-O0 -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-und
efined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -Wl,--build
-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noe
xecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,my.so -o
$outpath/my.so $mypath/a.o $mypath/b.o $install_dir/lib/libssl.a $install_dir/li
b/libcrypto.a -ldl my.a -lz -llog -lm "/home/choury/bin/Android/android-sdk-linux
/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/arm64-v8a/libsupc++.a" "/home/
choury/bin/Android/android-sdk-linux/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9
/libs/arm64-v8a/libgnustl_shared.so"
我使用 cmake 构建项目,其中的 Openssl 部分:
set(OPENSSL_INCLUDE_DIR ${OPENSSL_ROOT_DIR}/include)
set(OPENSSL_LIBRARIES ${OPENSSL_ROOT_DIR}/lib)
set(OPENSSL_CRYPTO_LIBRARY ${OPENSSL_LIBRARIES}/libcrypto.a)
set(OPENSSL_SSL_LIBRARY ${OPENSSL_LIBRARIES}/libssl.a)
find_package(OpenSSL REQUIRED IMPORTED)
OPENSSL_ROOT_DIR 在 build.gradle 中使用 $install_dir 设置。
【问题讨论】:
-
我们不知道您是如何构建库的,所以我们无法判断。
-
您是否使用
no-dgram或-DOPENSSL_NO_DGRAM配置了OpenSSL?执行nm libssl.a | grep -i BIO_new_dgram并查看符号是否可用。否则,请说明 OpenSSL 所在的位置,并显示您的链接命令my.so。 -
@jww 添加到问题中。
-
@AlexCohn 太好了,它解决了我的问题,非常感谢!
标签: android-ndk openssl