Qt的静态构建:Qt5Network链接错误

11
我正在尝试制作一个支持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

包含目录和库目录都是有效的。我在 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维基中的优秀教程操作,但是得到了相同的错误。

如果这确实是Qt的错误,就像Frank在他的评论中建议的那样,如果有人能够建议最后一个应该工作的版本,那将非常有用。

更新3

bugreports.qt.io上,我收到了这不是一个错误的看法:

您实际上没有告诉构建程序链接openssl库。 http://doc.qt.io/qt-5/ssl.html给出以下示例:

OPENSSL_LIBS='-L/opt/ssl/lib -lssl -lcrypto' ./configure -openssl-linked

当然,你需要根据你的编译器和库位置进行一些调整。

在所引用的文档页面中,给出了以下示例:

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

虽然不完全是我想要的,但已经有了进展:

我下载了最近发布的Qt 5.4.2的源代码,并使用其中的“-openssl”开关创建了一个动态链接的OpenSSL的静态构建。

我仍在寻找一种静态链接OpenSSL的解决方案。我仍然遇到相同的链接错误。


@FrankOsterfeld 谢谢,我已经将其报告为一个 bug。https://bugreports.qt.io/browse/QTBUG-46405 我本意是指 5.4.1 版本,对于不准确之处请见谅。 - Gábor Angyal
@FrankOsterfeld 我得到的答案是这不是一个错误,但我个人还没有完全排除它。你能建议一个试用的Qt版本吗? - Gábor Angyal
@KubaOber 好说不好做啊。我已经下载了Windows版的OpenSSL官方二进制分发包,但它并没有包含它。我不知道该怎么办。 - Gábor Angyal
@GáborAngyal 那就自己构建,或者从闪亮之光制作的非官方二进制版本中下载。我已经这样做了好几年,很有效。 - Kuba hasn't forgotten Monica
@KubaOber 你使用的 OpenSSL 和 Qt 版本是哪个? - Gábor Angyal
显示剩余5条评论
5个回答

2
这是我如何在Windows上使用MSVC 2013构建带有SSL和MySQL支持的Qt 5.7.1的方法:

确保Perl,Python和Ruby可以在PATH环境变量中找到。

从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版本创建一个新的工具包用于您的项目:


0

我刚刚花了一整天的时间处理静态构建,对我有效的方法是:

https://github.com/alberthdev/alberthdev-misc/wiki/Building-Qt-v5.6-Statically-on-Windows

此外,您必须注意我使用的是openssl-1.0.1r,因为新版本的构建算法和.dll名称与说明中的不同,因此说明中的算法无法与它们一起使用,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更正为适合您的文件结构。所有其他步骤都按照链接下的说明确切执行。

0

这是一个老问题,但我会回答。 这取决于 OpenSSL 的版本。如果您使用的版本低于 1.1.0,则上述序列可能没有问题,但根据我的经验,在使用 1.1.1 时,它不需要 OPENSSL_LIBS="-LC:\OpenSSL-Win32\lib -lssl -lcrypto"。配置后,有一个名为 QtNetowrk 的项目,它会显示是否检测到 OpenSSL 库。以下适用于 1.1.1 静态和 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

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

-platform win32-msvc2012-mt 指向 -MT 编译器选项 makespec,因此应用程序也使用 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。


-1

我遇到了同样的问题,我认为问题在于我们首先没有使用ssl进行构建,因此src/network/Makefiles没有重新生成

当我删除它们并再次运行configure时,问题得以解决

希望这可以帮到你


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接