Use OpenSSL in Qt C++(在 Qt C++ 中使用 OpenSSL)
问题描述
我得到了一个示例项目,它使用 QSslSocket 和 QSslCertificate 从 SSL 证书(Qt 5.7、Windows 10)获取信息.QSslSocket::supportsSsl() 函数返回 false,我在运行时收到这些错误:
I got a sample projct that uses QSslSocket and QSslCertificate to get information from a SSL certificate (Qt 5.7, Windows 10). QSslSocket::supportsSsl() function returns false and I get these errors at runtime:
qt.network.ssl: QSslSocket: cannot call unresolved function SSLv23_client_method
qt.network.ssl: QSslSocket: cannot call unresolved function SSL_CTX_new
qt.network.ssl: QSslSocket: cannot call unresolved function SSL_library_init
qt.network.ssl: QSslSocket: cannot call unresolved function ERR_get_error
所以我编译了 OpenSSL_1.1.0 并将其链接到我的项目:
So I compiled OpenSSL_1.1.0 and linked it to my project:
INCLUDEPATH += . "C:/OpenSSL-Win32/include/" LIBS +=
-L"C:/OpenSSL-Win32/lib/" -llibcrypto -llibssl
但还是一样的错误.我下载了 OpenSSL 安装程序,但还是一样.
But still same errors. I downloaded OpenSSL installer and still the same.
奇怪的是 QSslSocket::sslLibraryBuildVersionString() 返回 OpenSSL 1.0.2g 1 Mar 2016,即使我编译并安装了 OpenSSL_1.1.0.
Weird is QSslSocket::sslLibraryBuildVersionString() returns OpenSSL 1.0.2g 1 Mar 2016, even though I compiled and installed OpenSSL_1.1.0.
我知道我遗漏了一个简单的细节.请告诉我是什么.谢谢.
I know I'm missing a simple detail. Please tell me what is it. Thanks.
推荐答案
来自文档:
QSslSocket::sslLibraryBuildVersionString() 返回 SSL 库的版本字符串在编译时使用.(强调我的)
QSslSocket::sslLibraryBuildVersionString() Returns the version string of the SSL library in use at compile time. (emphasis mine)
你从它得到结果并不意味着 Qt 可以访问 OpenSSL,只是它是针对某个版本编译的.这让您知道如果动态链接(默认情况下),您应该在运行时提供哪个二进制兼容版本.
That you get a result from it doesn't mean that Qt has access to OpenSSL, only that it was compiled against a certain version. That lets you know what binary-compatible version you should provide at runtime if it's dynamically linked (as it is by default).
您想检查 QSslSocket::sslLibraryVersionNumber() - [...] 库的版本在运行时使用(重点是我的).
You want to check QSslSocket::sslLibraryVersionNumber() - [...] the version of the library in use at run-time (emphasis mine).
Qt 可能会尝试在 PATH 中找到 OpenSSL dll 的副本,如果没有,则在 QCoreApplication::libraryPaths 给出的路径中.在尝试使用 OpenSSL 之前,您应该将 OpenSSL dll 的位置添加到其中之一.
Qt will presumably attempt to find a copy of OpenSSL dlls in PATH, and if not, in the paths given by QCoreApplication::libraryPaths. You should add the location of OpenSSL dlls to either one before attempting to use OpenSSL.
这篇关于在 Qt C++ 中使用 OpenSSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Qt C++ 中使用 OpenSSL
基础教程推荐
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
