C++ Qt QT5网络链接错误的静态构建

C++ Qt QT5网络链接错误的静态构建,c++,qt,deployment,compilation,static-linking,C++,Qt,Deployment,Compilation,Static Linking,我正在尝试使用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目录是有效的。我在Qt

我正在尝试使用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
配置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

我也试着遵循中的伟大教程,并得到了相同的错误

如果这确实是一个Qt错误,正如Frank在中所建议的那样,如果有人能推荐Qt的最后一个版本,这将非常有用

更新3

关于我收到的意见,这不是一个bug:

实际上,您还没有告诉构建链接openssl库。 给出以下示例:

OPENSSL_LIBS='-L/opt/ssl/lib-lssl-lcrypto'/configure -openssl链接

您需要根据编译器和的库位置对其进行调整 当然

在参考文档页面上给出了该示例:

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

在我编译的OpenSSL构建中,或者在二进制发行版中,我都找不到ssl或加密库。不过我有标题。我只有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天前)发布的Qt5.4.2的源代码,通过这些源代码,我能够创建一个带有动态链接的OpenSSL(-OpenSSL开关)的静态构建


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

不久前,我以某种方式使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

我刚刚花了大约一天的时间处理这个静态构建,对我来说有效的是:

另外,您必须注意,我使用了
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
,以适合您的文件结构。所有其他步骤都是按照链接下的说明中所述巧妙地进行的

这就是我如何使用MSVC 2013在Windows上使用SSLMySQL支持构建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 
qt5vars.bat 
perl init-repository
确保签出提交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
最后,要成功配置和编译库(使用调试和发布版本),请确保
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版本,并创建一个新的工具包用于您的项目:


我遇到了同样的问题,我认为问题在于我们首先在没有ssl的情况下进行构建,并且不会重新生成src/network/makefile

当我删除它们并再次运行configure时,我成功了


希望这有帮助这是一个老问题,但我会给出答复 这取决于开放式ssl的版本。如果您使用的是低于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

很可能是一个Qt错误,那么在Qt-JIRA中报告它是值得的。当你说“Qt5.4”时,你是指5.4.0还是5.4.1?@FrankOsterfeld谢谢你,我已经把它报告为一个bug。我的意思是5.4.1,很抱歉不准确。@Frankosterfield我得到的答案是,这不是一个bug,但就我个人而言,我还没有完全判定它是错误。你能推荐一个Qt版本来试用吗?“在我编译的OpenSSL版本中找不到ssl或加密库”好吧,先解决这个问题,你的问题与Qt无关。@KubaOber说起来容易做起来难。我已经下载了OpenSSL for Windows的官方二进制发行版,但它不包含它。我不知道我能做些什么。
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