undefined reference to `dlopen‘ ‘SSL_library_init‘ `X509_certificate_type‘

使用Crow的时候需要注意crow依赖asio依赖OpenSSL,asio要求1.22以上版本,我使用的是1.26.0;

这个版本的asio要求OpenSSL是1.0.2,其他版本我得机器上编不过,ubuntu上默认带的OpenSSL是1.1.1;

所以我下载了OPENSSL1.2.0重装,地址: https://www.openssl.org/source/old/

编译cpp启用Crow的SSL时会出现一些问题:

比如:

  • 1 undefined reference to `SSL_library_init'

出现这个提示需要在编译时指定链接 crypto 和 ssl 库

  • 2 undefined reference to `dlopen'

出现这个提示需要在编译时指定链接 dl 库

  • 3 undefined reference to `X509_certificate_type'

出现这个提示需要在编译时指定链接openssl的位置;

  • 4 以上需要指定的库和地址都加上之后还是报错,可能是指令顺序问题;
    例如

    // ×
    g++ example_ssl.cpp -L/usr/local/openssl/lib -lssl -ldl -lcrypto -DCROW_ENABLE_SSL=1 -o ssl_example -std=c++11 -lpthread

    // √
    g++ example_ssl.cpp -L/usr/local/openssl/lib -lssl -lcrypto -DCROW_ENABLE_SSL=1 -o ssl_example -std=c++11 -lpthread -ldl

上面两行只是调整了 -ldl 所在的位置,就会消除部分错误,

具体原因参考

https://qastack.cn/programming/956640/linux-c-error-undefined-reference-to-dlopen

https://stackoverflow.com/questions/11893996/why-does-the-order-of-l-option-in-gcc-matter/11894098#11894098

相关推荐
魏 无羡6 小时前
k8s ssl 漏洞修复
容器·kubernetes·ssl
weixin_387002151 天前
Openssl之SM2加解密命令
安全·ubuntu·密码学·ssl·命令模式
三天不学习2 天前
使用 Certbot 自动获取和更新 Let‘s Encrypt SSL 证书
网络·网络协议·ssl·cerbot
Wlq04153 天前
三种安全协议 IPSec & SSL & PGP
网络·安全·ssl
兮动人3 天前
宝塔面板开始ssl后,使用域名访问不了后台管理
网络·网络协议·ssl·宝塔面板
帝恩思科技3 天前
IP证书 vs SSL证书:数字安全的两条技术路径与未来博弈
网络协议·tcp/ip·安全·网络安全·ssl·ip证书
蜗牛去旅行吧4 天前
解决 `pip is configured with locations that require TLS/SSL` 错误
网络协议·ssl·pip
若云止水4 天前
Ubuntu 下 nginx-1.24.0 源码分析 -ngx_ssl_error 函数
运维·nginx·ssl
LeonNo114 天前
TLS和SSL的区别
网络·网络协议·ssl
忧虑的乌龟蛋4 天前
HTTP 与 HTTPS:协议详解与对比
网络·websocket·网络协议·http·微信小程序·https·ssl