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

相关推荐
hoho_1218 小时前
目标主机使用了不受支持的SSL加密算法【原理扫描】
网络·网络协议·ssl
wapicn9919 小时前
HTTPS原理详解:从握手到证书链验证,一张SSL证书的完整生命周期
网络协议·https·ssl
落叶_Jim21 小时前
2026年阿里云腾讯云免费SSL证书限额20张不够用怎么办
阿里云·腾讯云·ssl
難釋懷2 天前
Nginx-CA 签名
服务器·nginx·ssl
齐齐大魔王2 天前
OpenSSL 原理
运维·网络·nginx·ssh·ssl
蜀道山老天师2 天前
Docker 部署 Nginx Proxy Manager:可视化反向代理 + SSL 证书一键配置
nginx·docker·ssl
小二·2 天前
Nginx 高级配置实战:负载均衡/SSL/缓存优化
nginx·负载均衡·ssl
古道青阳3 天前
深入密码学内核:对称/非对称原理、PKI体系及C语言实现
网络协议·https·ssl
GlobalSign数字证书3 天前
中小企业的 SSL/TLS 证书管理,有更轻量的方案
数据库·网络协议·ssl
Aubrey-J4 天前
老版本Gitlab SSL证书自动续期错误KeyError: key not found: “token“解决
网络协议·gitlab·ssl