我有一个非常简单的代码:
#include <openssl/sha.h>
int main() {
SHA_CTX sha1;
SHA_Init(&sha1);
}
我已经安装了 libssl-dev
和 libcrypto++-dev
:
但是,我使用以下命令构建失败:
$ gcc -lcrypto -lssl main.c
/tmp/ccfnCAxT.o: In function `main':
main.c:(.text+0x1f): undefined reference to `SHA1_Init'
collect2: error: ld returned 1 exit status
$
$ gcc -lssl main.c
/tmp/ccfnCAxT.o: In function `main':
main.c:(.text+0x1f): undefined reference to `SHA1_Init'
collect2: error: ld returned 1 exit status
平台:Ubuntu 16.04
最佳答案
-lssl
不需要,-lcrypto
就够了,而且必须在最后:
gcc -o main main.c -lcrypto
(或者您希望在 -o
之后调用程序的任何内容)
关于使用 libssl 编译不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50518881/