openssl编程编译错误undefined reference to `SSL_get1_peer_certificate‘解决方法

问题:

[100%] Linking C executable example_ssl_serv
CMakeFiles/example_ssl_serv.dir/example_ssl_serv.c.o: In function `main':
example_ssl_serv.c:(.text+0x49e): undefined reference to `SSL_get1_peer_certificate'
collect2: error: ld returned 1 exit status
CMakeFiles/example_ssl_serv.dir/build.make:94: recipe for target 'example_ssl_serv' failed
make[2]: *** [example_ssl_serv] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/example_ssl_serv.dir/all' failed
make[1]: *** [CMakeFiles/example_ssl_serv.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
root@cd2e1925ffbe:/work/CyberSecurityCode/sslservexample# ^C

原因:

        SSL_get1_peer_certificate源码里调用的是SSL_get_peer_certificate,而报错的是SSL_get1_peer_certificate这个函数,所以问题应该出现在库里面而不是源码里面。具体原因不太确定,感觉和某个编译选项有关

解决方法 :

        执行以下命令重新编译安装

进入openssl目录

cd /work/download/openssl-1.1.1o/

      设置confgi

./config --prefix=/usr/local --openssldir=/etc/ssl --libdir=lib enable-ssl3 enable-ssl3-method enable-weak-ssl-ciphers -DOPENSSL_NO_GOST zlib shared

make和make install

make
make install

 使用新版Openssl

ln -s /usr/local/bin/openssl /usr/bin/openssl
ln -s /usr/local/include/openssl/ /usr/include/openssl

 跟新动态链接库


echo "/usr/local/lib/" >> /etc/ld.so.conf
ldconfig

你可能感兴趣的:(ssl,网络协议,网络)