在 Qt C++ 中使用 OpenSSL [英] Use OpenSSL in Qt C++

查看:53
本文介绍了在 Qt C++ 中使用 OpenSSL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了一个示例项目,它使用 QSslSocketQSslCertificate 从 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆