【问题标题】:Undefined symbols for architecture arm64: _BN_new架构 arm64 的未定义符号:_BN_new
【发布时间】:2021-08-23 09:56:21
【问题描述】:

我正在尝试编译这个超级简单的代码:

#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 进行了完全相同的尝试,它给出了相同的结果

【问题讨论】:

    标签: c macos gcc


    【解决方案1】:

    如您所见,此函数是在 libcrypto 库中定义的,但您实际上并未与该库链接。您需要将-lcrypto 添加到链接器命令行的末尾。

    -L 选项指定要搜索使用-l 选项请求的库的目录,但它本身并不向链接添加任何库。

    【讨论】:

      猜你喜欢
      • 2013-10-13
      • 1970-01-01
      • 2021-07-25
      • 2018-11-14
      • 2015-12-05
      • 1970-01-01
      相关资源
      最近更新 更多