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

查看:369
本文介绍了在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天全站免登陆