我使用的是运行 Catalina 10.15.1
的 Intel Mac
我正在尝试使用 libsodium
使用 gcc Apple clang 版本 11.0.0 (clang-1100.0.33.12)
我都尝试通过 home-brew
安装 libsodium
并手动编译(成功),但是,当尝试使用 libsodium
时> 我收到此错误:
Undefined symbols for architecture x86_64:
"_crypto_generichash", referenced from:
_main in sodium-ae2fd0.o
"_sodium_init", referenced from:
_main in sodium-ae2fd0.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
这是基本代码,使用libsodium: stable 1.0.18 (bottled), HEAD
1 #include <sodium.h>
2
3 int main(void)
4 {
5
6 sodium_init();
7
8 #define MESSAGE ((const unsigned char *) "Arbitrary data to hash")
9 #define MESSAGE_LEN 22
10
11 unsigned char hash[crypto_generichash_BYTES];
12
13 crypto_generichash(hash, sizeof hash,
14 MESSAGE, MESSAGE_LEN,
15 NULL, 0);
16
17 return 0;
18 }
有什么想法吗?
最佳答案
问题可能不在于 libsodium 安装,而在于示例应用程序的编译方式。
为了在编译C程序时链接库(除了隐式链接的C库之外),需要添加-l<library name>
标记到编译命令行:
cc -Wall -W -o example example.c -lsodium
关于c - macOS 上的 Libsodium,x86_64 的 undefined symbol ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59102480/