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

相关推荐
醉颜凉1 天前
超详细图解:HTTPS 中的 SSL/TLS 完整握手过程(面试必背)
面试·https·ssl
wapicn992 天前
设置好这一步,让你的SSL证书在到期前自动续期,永不过期
网络·网络协议·ssl
KnowSafe5 天前
自动化+智能化:证书生命周期管理的双重革命
ssl·itrustssl·trustasia·证书自动化
KnowSafe6 天前
CaaS vs 传统管理:证书即服务的颠覆性优势
https·ssl
ReaF_star6 天前
【安全】SSL证书更新操作手册(Nginx+Cloudflare+acme.sh)
nginx·安全·ssl
KnowSafe6 天前
证书自动化解决方案哪家更可靠?
运维·服务器·安全·https·自动化·ssl
KnowSafe6 天前
2026年证书自动化解决方案选型指南
运维·安全·自动化·ssl·itrustssl
日取其半万世不竭6 天前
WordPress建站 + 免费SSL证书配置完整教程
网络·网络协议·ssl
KnowSafe6 天前
证书自动化革命:CaaS如何重塑企业数字信任体系
https·ssl·itrustssl·trustasia
落叶_Jim6 天前
2026年最新Let’s Encrypt免费SSL证书申请与自动续期完整指南(泛域名证书)
安全·https·ssl