我正在尝试编译这个超级简单的代码:
#include <openssl/bn.h>
int main(void)
{
BIGNUM *k = BN_new();
}我使用以下命令:
gcc-11 test.c -I/opt/homebrew/opt/openssl@1.1/include -L/opt/homebrew/opt/openssl@1.1/lib我得到了
gcc-11 test.c -I/opt/homebrew/opt/openssl@1.1/include -L/opt/homebrew/opt/openssl@1.1/lib
Undefined symbols for architecture arm64:
"_BN_new", referenced from:
_main in ccRnO859.o
ld: symbol(s) not found for architecture arm64
collect2: error: ld returned 1 exit status以下是更多信息:
% file $(which gcc-11)
/opt/homebrew/bin/gcc-11: Mach-O 64-bit executable arm64
% gcc-11 --version
gcc-11 (Homebrew GCC 11.1.0) 11.1.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
% file /opt/homebrew/opt/openssl@1.1/lib/libcrypto.dylib
/opt/homebrew/opt/openssl@1.1/lib/libcrypto.dylib: Mach-O 64-bit dynamically linked shared library arm64
% nm -gU /opt/homebrew/opt/openssl@1.1/lib/libcrypto.dylib|grep _BN_new
00000000000311bc T _BN_new编辑:我用一个x86_64版本的GCC和OpenSSL尝试了完全相同的结果,它给出了相同的结果
发布于 2021-06-06 02:44:23
正如您所发现的,该函数是在libcrypto库中定义的,但是您实际上并没有链接到该库。您需要将-lcrypto添加到链接器命令行的末尾。
-L选项指定要搜索使用-l选项请求的库的目录,但本身不会将任何库添加到链接中。
https://stackoverflow.com/questions/67852583
复制相似问题