gpt4 book ai didi

c - 链接C文件错误: linker command failed with exit code 1

转载 作者:行者123 更新时间:2023-11-30 20:01:22 39 4
gpt4 key购买 nike

我有三个文件:rsa.c、prf.c 和 rsa-test.c。

我使用gcc -c rsa.cgcc -c prf.cgcc -c rsa-test.c来获取.o 文件。

编辑:我将 rsa.c 和 prf.c 包含在 rsa-test.c 中。

然后我使用 gcc -o test rsa.o prf.o rsa-test.o 编译 .o 文件。

编译时出现以下错误。 o 三个文件的文件。

Undefined symbols for architecture x86_64:
"_EVP_sha512", referenced from:
randBytes(unsigned char*, unsigned long) in prf.o
"_HMAC", referenced from:
randBytes(unsigned char*, unsigned long) in prf.o
"_SHA512", referenced from:
setSeed(unsigned char*, unsigned long) in prf.o
"___gmpz_add_ui", referenced from:
randBytes(unsigned char*, unsigned long) in prf.o
"___gmpz_clear", referenced from:
rsa_shredKey(_RSA_KEY*) in rsa.o
"___gmpz_export", referenced from:
zToFile(__sFILE*, __mpz_struct*) in rsa.o
"___gmpz_import", referenced from:
zFromFile(__sFILE*, __mpz_struct*) in rsa.o
"___gmpz_init", referenced from:
rsa_initKey(_RSA_KEY*) in rsa.o
setSeed(unsigned char*, unsigned long) in prf.o
"___gmpz_limbs_read", referenced from:
randBytes(unsigned char*, unsigned long) in prf.o
"___gmpz_limbs_write", referenced from:
rsa_shredKey(_RSA_KEY*) in rsa.o
"___gmpz_set_ui", referenced from:
rsa_initKey(_RSA_KEY*) in rsa.o
setSeed(unsigned char*, unsigned long) in prf.o
"___gmpz_size", referenced from:
zToFile(__sFILE*, __mpz_struct*) in rsa.o
rsa_numBytesN(_RSA_KEY*) in rsa.o
rsa_shredKey(_RSA_KEY*) in rsa.o
randBytes(unsigned char*, unsigned long) in prf.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我不确定是什么导致了这个错误。链接器似乎是问题所在,因为我在 rsa-test.c 中使用 rsa.c 和 prf.c 中的函数,这就是导致此问题的原因。

如果您想测试我的文件,请告诉我,我会将其发布。

最佳答案

您需要通过向 gcc -o 命令添加链接标志来链接到您正在使用的库。

看起来您正在使用 GMP,因此该标志应该是 -lgmp

如果涉及的其他库是 OpenSSL,请尝试 -lcrypto 或参见 here如果您从源代码构建它。

gcc -o test_linked.exe rsa.o prf.o rsa-test.o -lgmp -lcrypto

关于c - 链接C文件错误: linker command failed with exit code 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32707511/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com