[英]How to install OpenSSL 1.1.0 for Qt on Windows?
我的目標是使用QNetworkRequest
和QNetworkAccessManager
通過SSL連接從網頁上獲取源代碼(或圖像)。
OpenSSL 1.1.0不適用於Qt 5.8! 在Edit 2中查找安裝解決方案!
首先嘗試:獲取ssleay32.lib和libeay32.lib並將它們復制到debug和release文件夾中。 不要工作
第二次嘗試:(由於廢話而刪除),但是它不再起作用。
代碼(適用於正常的http):
QUrl url = QUrl(name);
data.clear();
QNetworkRequest *request = new QNetworkRequest(url);
request->setRawHeader("User-Agent", userAgent);
QSslConfiguration sslConfiguration(QSslConfiguration::defaultConfiguration());
request->setSslConfiguration(sslConfiguration);
reply = webCtrl->get(*request);
connect(webCtrl, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
connect(reply, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
connect(reply, SIGNAL(finished()), this, SLOT(onReplyFinished()));
錯誤訊息:
qt.network.ssl: QSslSocket: cannot call unresolved function d2i_DHparams
qt.network.ssl: QSslSocket: cannot call unresolved function DH_free
qt.network.ssl: QSslSocket: cannot call unresolved function d2i_DHparams
qt.network.ssl: QSslSocket: cannot call unresolved function DH_free
qt.network.ssl: QSslSocket: cannot call unresolved function d2i_DHparams
qt.network.ssl: QSslSocket: cannot call unresolved function DH_free
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
qt.network.ssl: QSslSocket: cannot call unresolved function ERR_get_error
Error creating SSL context ()
編輯1:我發現此 Artikel和OpenSSL 1.1.0將與Qt 5.10一起使用,但在Qt 5.8中無法使用。 在此 Artikel中,我找到了QSslSocket::sslLibraryBuildVersionString()
命令,我需要OpenSSL版本: OpenSSL 1.0.2h 3 May 2016
。
稍后,我將簽出其他OpenSSL版本,並編輯此帖子(不管它是否有效)。
編輯2: OpenSSL 1.0.2h 3 May 2016
下載OpenSSL 1.0.2h 3 May 2016
然后安裝7zip和Perl。 解壓縮openSSL文件夾,然后按照INSTALL.W64
。 轉到bin
文件夾,將libeay32-xxx.dll
和ssleay32-xxx.dll
到應用程序文件夾,並將文件重命名為libeay32.dll
和ssleay32.dll
。 謝謝@ [Max Go]。
現在,SSL連接最終完成了,但是當我關閉應用程序並且在運行時使用了Web連接時,我收到一條錯誤消息。
onlineTest.exe中0x000000007772D1CB(ntdll.dll)處的異常:0xC0000005:訪問沖突讀取位置0x0000000000000074。
VS2015調試窗口“ mem.c”行443:
free_debug_func 0x0000000000000000 void(*)(void *, int)
free_func 0x000007fee778b1ba {libeay32.dll!free} void(*)(void *)
str 0x0000000002500cf0 void *
編輯3:我忘了編譯-d調試.dll。 只需將編譯器模式更改為Debug,生成Debug .dll,然后在不使用-d的情況下重命名(如果需要),然后將debug .dll復制到debug文件夾,將普通.dll復制到release文件夾。
這是我用來從Visual Studio提示自動構建OpenSSL的腳本。 根據啟用的編譯器,它將構建32位或64位庫。
前提條件(必須在PATH中):
:: Configurable Options
:: If you have jom available, set it to jom - it speeds up the build.
@set JOM=nmake
:: Choose a static or dynamic build
@set LIBTYPE=dynamic
:: OpenSSL version in the 1.0.2 series
@set SRC=openssl-1.0.2k
@if "%VSCMD_ARG_TGT_ARCH%"=="x86" (
@set BITS=32
@set DST=OpenSSL-Win32
@set CONFIG=VC-WIN32
@set SETUP=ms\do_nasm
) else if "%VSCMD_ARG_TGT_ARCH%"=="x64" (
@set BITS=64
@set DST=OpenSSL-Win64
@set CONFIG=VC-WIN64A
@set SETUP=ms\do_win64a
) else goto no_vscmd
@if "%LIBTYPE%"=="static" (
@set LIBTYPE=nt
) else if "%LIBTYPE%"=="dynamic" (
@set LIBTYPE=ntdll
) else goto no_libtype
@echo Building %SRC% for %BITS% bits.
@echo - Downloading
@perl ^
-e "use LWP::Simple;" ^
-e "mirror('https://www.openssl.org/source/%SRC%.tar.gz', '%SRC%.tar.gz');"
@echo - Decompressing
@if not exist %SRC%.tar.gz goto no_archive
@rmdir /S /Q %SRC% %DST% 2>NUL
@7z x -bsp2 -y %SRC%.tar.gz >NUL && ^
7z x -bsp2 -y %SRC%.tar >NUL && ^
del %SRC%.tar
@if errorlevel 1 goto unpack_failed
@if not exist %SRC% goto no_source
@echo - Building
@pushd %SRC%
@perl Configure %CONFIG% --prefix=%~dp0..\%DST% && ^
call %SETUP% && ^
nmake -f ms\%LIBTYPE%.mak init && ^
%JOM% -f ms\%LIBTYPE%.mak "CC=cl /FS" && ^
%JOM% -f ms\%LIBTYPE%.mak test && ^
nmake -f ms\%LIBTYPE%.mak install || goto build_failed
@popd
@rmdir /S /Q %SRC%
@echo Build has succeeded.
@goto :eof
:no_libtype
@echo Error: LIBTYPE must be either "static" or "dynamic">&2
@exit /b 1
:no_archive
@echo Error: can't find %SRC%.tar.gz - the download has failed :(>&2
@exit /b 1
:unpack_failed
@echo Error: unpacking has failed.>&2
@exit /b %errorlevel%
:no_source
@echo Error: can't find %SRC%\>&2
@exit /b 1
:build_failed
@echo The build had failed.>&2
@popd
@exit /b 2
:no_vscmd
@echo Use vcvarsall x86 or vcvarsall x64 to set up the Visual Studio>&2
@echo build environment first.>&2
@exit /b 100
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.