我正在尝试使用OpenSSL支持进行Qt(版本5.4.1)的静态构建。我按如下方式对其进行了配置:
configure -opensource -release -c++11 -static -platform win32-msvc2013
-openssl-linked -I C:\OpenSSL-Win32\include
-L C:\OpenSSL-Win32\lib\VC\static
-nomake examples -nomake tests
include和lib目录有效。我在Qt5Network.lib
中收到大量链接错误。
Qt5Network.lib(qhttpnetworkconnectionchannel.obj) : error LNK2019: unresolved ex
ternal symbol "public: static class QSharedPointer<class QSslContext> __cdecl QS
slSocketPrivate::sslContext(class QSslSocket *)" (?sslContext@QSslSocketPrivate@
@SA?AV?$QSharedPointer@VQSslContext@@@@PAVQSslSocket@@@Z) referenced in function
"protected: void __thiscall QHttpNetworkConnectionChannel::_q_connected(void)"
(?_q_connected@QHttpNetworkConnectionChannel@@IAEXXZ)
Qt5Network.lib(qhttpprotocolhandler.obj) : error LNK2019: unresolved external sy
mbol "public: __int64 __thiscall QSslSocket::encryptedBytesToWrite(void)const "
(?encryptedBytesToWrite@QSslSocket@@QBE_JXZ) referenced in function "private: vi
rtual bool __thiscall QHttpProtocolHandler::sendRequest(void)" (?sendRequest@QHt
tpProtocolHandler@@EAE_NXZ)
C:\Qt\5.4\qtbase\bin\xmlpatterns.exe : fatal error LNK1120: 31 unresolved extern
als
jom: C:\Qt\5.4\qtxmlpatterns\tools\xmlpatterns\Makefile [release] Error 2
jom: C:\Qt\5.4\qtxmlpatterns\tools\Makefile [sub-xmlpatterns-make_first] Error 2
jom: C:\Qt\5.4\qtxmlpatterns\Makefile [sub-tools-make_first] Error 2
jom: C:\Qt\5.4\Makefile [module-qtxmlpatterns-make_first] Error 2
在没有OpenSSL支持之前,我能够创建静态构建。错误消息还表明问题与OpenSSL有关。
有没有人有想法解决这个问题?
更新
这些配置产生了同样的错误:
配置1:
configure -opensource -release -c++11 -static -platform win32-msvc2013
-openssl-linked -I C:\OpenSSL-Win32\include -L C:\OpenSSL-Win32\lib\VC\static
OPENSSL_LIBS="-llibeay32MT -lssleay32MT" -nomake examples -nomake tests
配置2:
configure -opensource -release -c++11 -static -platform win32-msvc2013
-openssl -I C:\OpenSSL-Win32\include -L C:\OpenSSL-Win32
-nomake examples -nomake tests
更新2
我也尝试过按照qBittorrent wiki中的精彩教程,并得到同样的错误。
如果这确实是一个Qt错误,正如弗兰克在his comment中所建议的那样,如果有人可以推荐Qt的最后一个版本,那么它也会非常有用。
更新3
在bugreports.qt.io我收到了意见,这不是错误:
您实际上没有告诉构建链接openssl库。 http://doc.qt.io/qt-5/ssl.html给出了以下示例:
OPENSSL_LIBS =' - L / opt / ssl / lib -lssl -lcrypto'./configure -openssl联
您需要为您的编译器和库位置调整它 当然。
在推荐的文档页面上,给出了这个例子:
OPENSSL_LIBS='-L/opt/ssl/lib -lssl -lcrypto' ./configure -openssl-linked
我没有在我编译的OpenSSL构建中找到ssl或crypto库,也没有在二进制分发中找到。我确实有标题。我只有ssleay32和libeay32库。
configure命令提示将这些库设置为上述变量:
NOTE: When linking against OpenSSL, you can override the default
library names through OPENSSL_LIBS
and optionally OPENSSL_LIBS_DEBUG/OPENSSL_LIBS_RELEASE
For example:
configure -openssl-linked OPENSSL_LIBS="-lssleay32 -llibeay32"
通过设置此变量,我仍然会遇到相同的错误。
更新5
不完全是我想要的,但向前迈进了一步:
我已经下载了最近(4天前)发布的Qt 5.4.2的源代码,并且我能够使用动态链接的OpenSSL(-openssl开关)创建静态构建。
我仍在寻找静态链接OpenSSL的解决方案。我仍然有相同的链接错误。
答案 0 :(得分:2)
这是我使用 MSVC 2013 在Windows上使用 SSL 和 MySQL 支持构建 Qt 5.7.1 的方法:
确保可以在PATH环境变量中找到Perl,Python和Ruby。
从github存储库下载Qt:
cd C:\Qt
git clone https://github.com/qt/qt5.git
cd C:\Qt\qt5
git checkout 5.7
请务必结帐提交 36e7cff94fbb4af5d8de6739e66164c6e6873586 。这时,检查5.7就是这样。
将以下内容放在位于C:\Qt\qt5
的 qt5vars.bat 中。如果您需要进行调整:
@echo off
REM Set up \Microsoft Visual Studio 2015, where <arch> is \c amd64, \c x86, etc.
CALL "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" x86
REM Edit this location to point to the source code of Qt
SET _ROOT=C:\Qt\qt5
SET PATH=%_ROOT%\qtbase\bin;%_ROOT%\gnuwin32\bin;%PATH%
REM Uncomment the below line when using a git checkout of the source repository
SET PATH=%_ROOT%\qtrepotools\bin;%PATH%
REM Uncomment the below line when building with OpenSSL enabled. If so, make sure the directory points
REM to the correct location (binaries for OpenSSL).
SET PATH=C:\OpenSSL-Win32\bin;%PATH%
REM When compiling with ICU, uncomment the lines below and change <icupath> appropriately:
REM SET INCLUDE=<icupath>\include;%INCLUDE%
REM SET LIB=<icupath>\lib;%LIB%
REM SET PATH=<icupath>\lib;%PATH%
REM Contrary to earlier recommendations, do NOT set QMAKESPEC.
SET _ROOT=
REM Keeps the command line open when this script is run.
cmd /k
之后,执行此文件并正确启动存储库:
qt5vars.bat
perl init-repository
最后,要成功配置和编译库(使用调试版和发行版),请确保configure
引用的路径在您的系统上也有效:
configure -static -static-runtime -debug-and-release -ssl -openssl -openssl-linked -qt-sql-mysql -opengl dynamic -platform win32-msvc2013 -prefix C:\Qt\qt5.7-msvc2013-static -nomake tests -nomake examples -I "C:\Program Files (x86)\MySQL\MySQL Connector.C 6.1\include" -I "C:\OpenSSL-Win32\include" -L "C:\Program Files (x86)\MySQL\MySQL Connector.C 6.1\lib" -L "C:\OpenSSL-Win32\lib\VC\static" OPENSSL_LIBS="-lUser32 -lAdvapi32 -lGdi32 -lCrypt32" OPENSSL_LIBS_DEBUG="-lssleay32MTd -llibeay32MTd" OPENSSL_LIBS_RELEASE="-lssleay32MT -llibeay32MT"
nmake
nmake install
到目前为止,一切都应该顺利而美丽地运行。现在,将Qt Creator配置为检测此新Qt版本并创建新工具包以用于您的项目:
答案 1 :(得分:0)
我不久以前在Qt 5.3上以某种方式使它工作得非常快:
configure -static -debug-and-release -platform win32-msvc2012-mt -openssl -I %OPENSSL_HOME%\include -L %OPENSSL_HOME% -nomake examples -nomake tests -confirm-license -opengl es2 -skip qtwebkit -skip qtwebkit-examples -skip qttools
where -platform win32-msvc2012-mt指向-MT编译器选项makepec,因此应用程序也使用MT。也可以在app .pro文件中使用它:
LIBS += -L$$PWD/../third-party/openssl/lib -llibeay32MT
LIBS += -L$$PWD/../third-party/openssl/lib -lssleay32MT
请确保在静态Qt构建尝试之间重新安装整个Qt Src目录,从我的观察来看,总是很难跟踪在新运行中破坏所有内容的剩余内容。
并将OPENSSL_HOME变量设置为ProjectDir \ third-party \ openssl
答案 2 :(得分:0)
我花了大约一天时间处理静态构建,对我来说有用的是:
https://github.com/alberthdev/alberthdev-misc/wiki/Building-Qt-v5.6-Statically-on-Windows
此外,您必须注意我使用openssl-1.0.1r
,因为新版本构建算法和.dll名称在示例中不同,因此指令alghorithm不适用于它们,openssl-1.0.1r
不是已弃用,所以没关系。
我也遇到了building.bat脚本的问题,所以这里有一个以适当的方式为我工作的那个:
..\qt-5.8.0\configure -opensource -confirm-license^
-prefix C:\Qt\Qt5.8.0-static^
-debug-and-release -ssl -openssl -openssl-linked -opengl dynamic^
-static -static-runtime -platform win32-msvc2015^
-no-compile-examples -nomake examples^
-L C:\OpenSSL-win32\lib -I C:\OpenSSL-win32\include OPENSSL_LIBS="-llibeay32 -lssleay32"
注意,我的“Build”目录不在“qt-5.8.0”目录中,所以请更正路径..\qt-5.8.0\configure
以适合您的文件结构。正如在链接下的说明中所说的那样,所有其他步骤都是狡猾的。
答案 3 :(得分:0)
这是一个古老的问题,但我会给予答复 这取决于open ssl的版本。如果使用的版本低于1.1.0,则上述顺序可能没问题,但是根据我的经验,使用1.1.1并不需要OPENSSL_LIBS =“-LC:\ OpenSSL-Win32 \ lib -lssl -lcrypto”。配置后,有一个名为QtNetowrk的项目,它显示是否已检测到openssl库。以下适用于1.1.1 static和qt 5.12.4
set OPENSSL_HOME=C:\OpenSSL-Win32
..\configure -static -debug-and-release -platform win32-msvc2019 -static-runtime -ssl -openssl -openssl-linked -I %OPENSSL_HOME%\include -L %OPENSSL_HOME%\lib
答案 4 :(得分:-1)
我遇到了同样的问题,我认为问题是我们首先构建没有ssl而且src / network / Makefiles没有重新生成
当我删除它们并再次运行configure时,我完成了
希望这有助于