0

我有一个非常简单的代码:

#include <openssl/sha.h>

int main() {
    SHA_CTX sha1;
    SHA_Init(&sha1);
}

我已经安装了libssl-devlibcrypto++-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

4

1 回答 1

1

-lssl不需要,-lcrypto就足够了,而且必须在最后:

gcc -o main main.c -lcrypto

(或者你希望你的程序被调用的任何东西-o

于 2018-05-24T23:59:11.050 回答