問題描述
我得到了一個示例項目,它使用 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的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!