openssl安装:遇到问题及解决方法

openssl安装:遇到问题及解决方法

gcc遇到的问题:

/usr/bin/ld: /tmp/ccaJXv8h.o: in function main': test_openssl.c:(.text+0xf): undefined reference to OPENSSL_init_crypto'
collect2: 错误:ld 返回 1

/usr/bin/ld: /tmp/ccoMj648.o: undefined reference to symbol 'OPENSSL_init_crypto@@OPENSSL_1_1_0'
/usr/bin/ld: /usr/lib64/libcrypto.so.1.1: error adding symbols: DSO missing from command line
collect2: 错误:ld 返回 1

/usr/bin/ld: /tmp/cc45EJ1R.o: in function main': test_openssl.c:(.text+0xf): undefined reference to OPENSSL_init_crypto'
collect2: 错误:ld 返回 1

gcc -o to test_openssl.c -I /usr/local/ssl/inlcude -L /usr/local/ssl/lib -lssl -lcrypto -ldl -lpthread

解决方案:

=======================================================================================================

gcc -o to test_openssl.c -I /usr/local/ssl/inlcude -L /usr/local/ssl/lib -lssl -lcrypto -ldl -lpthread

原因分析:

在链接这个库的时候一定要注意2个问题:

1.openssl库的版本问题,请直接链到你需要的openssl库路径,比如我的就是/usr/local/ssl/lib,

2.注意-lssl -lcrypto要写在-ldl -lpthread前面,这四个必须要。

相关知识:

-L :此选项是指定链接库的文件夹地址

-l(小写的L):-lssl 即是寻找/usr/local/openssl/lib目录下的 libssl.a 这个库,编译器会自动寻找 libssl.a或者libssl.so

-I(大写的i):指定头文件的文件夹地址

posted @ 2021-11-02 20:11  氧气2019  阅读(1422)  评论(0编辑  收藏  举报