Gáb*_*yal 11 c++ deployment qt 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
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
在没有OpenSSL支持的情况下,我能够创建静态构建.错误消息还表明,问题与OpenSSL有关.
有没有人有想法解决这个问题?
UPDATE
这些配置产生相同的错误:
配置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
Run Code Online (Sandbox Code Playgroud)
配置2:
configure -opensource -release -c++11 -static -platform win32-msvc2013
-openssl -I C:\OpenSSL-Win32\include -L C:\OpenSSL-Win32
-nomake examples -nomake tests
Run Code Online (Sandbox Code Playgroud)
更新2
我也尝试过按照qBittorrent wiki中的精彩教程,并得到同样的错误.
如果这确实是一个Qt错误,正如弗兰克在他的评论中所建议的那样,如果有人可以推荐Qt的最后一个版本,那么这也应该是有用的.
更新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
Run Code Online (Sandbox Code Playgroud)
我没有在我编译的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"
Run Code Online (Sandbox Code Playgroud)
通过设置此变量,我仍然会得到相同的错误.
更新5
不完全是我想要的,但向前迈进了一步:
我已经下载了最近(4天前)发布的Qt 5.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
Run Code Online (Sandbox Code Playgroud)
其中 -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
Run Code Online (Sandbox Code Playgroud)
确保在静态 Qt 构建尝试之间重新安装整个 Qt Src 目录,根据我的观察,总是很难跟踪破坏新运行中所有内容的剩余内容。
并将 OPENSSL_HOME 变量设置为 ProjectDir\third-party\openssl