I am trying to make a static build of Qt (version 5.4.1) with OpenSSL support. I configured it as follows:
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
The include and lib directories are valid. I am getting loads of linking errors in 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
I was able to create a static build before without OpenSSL support. The error messages also suggest, that the problem is associated to OpenSSL.
Does anyone has an idea to resolve this?
UPDATE
These configurations are producing the same error:
Configuration 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
Configuration 2:
configure -opensource -release -c++11 -static -platform win32-msvc2013
-openssl -I C:\OpenSSL-Win32\include -L C:\OpenSSL-Win32
-nomake examples -nomake tests
UPDATE 2
I also tried so follow the great tutorial in the qBittorrent wiki, and got the same errors.
If this is indeed a Qt bug, as Frank suggested in his comment, it would be also really useful if someone could suggest the last version of Qt, with which this should work.
UPDATE 3
On bugreports.qt.io I have received the opinion, that this is not a bug:
You haven't actually told the build to link the openssl libraries. http://doc.qt.io/qt-5/ssl.html gives the following example:
OPENSSL_LIBS='-L/opt/ssl/lib -lssl -lcrypto' ./configure -openssl-linked
You'll need to tweak it for your compiler and library locations of course.
On the referred documentation page this example is given:
OPENSSL_LIBS='-L/opt/ssl/lib -lssl -lcrypto' ./configure -openssl-linked
I do not find the ssl or the crypto libraries in the OpenSSL build I compiled, nor in the binary distribution. I do have the headers though. I only have the ssleay32 and libeay32 libraries.
The configure command does hint to set these libraries to the mentioned variable:
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"
By setting this variable I still get the same errors.
UPDATE 5
Not exactly what I wanted, but a step forward:
I have downloaded the sources for the recently (4 days ago) released Qt 5.4.2, and with that I was able to create a static build with a dynamicly linked OpenSSL (-openssl switch).
I am still looking for a solution to staticly link OpenSSL. I still have the same linking errors.
This is how I build Qt 5.7.1 with SSL and MySQL support on Windows using MSVC 2013:
Make sure Perl, Python and Ruby can be found in the PATH environment variable.
Download Qt from the github repository:
cd C:\Qt
git clone https://github.com/qt/qt5.git
cd C:\Qt\qt5
git checkout 5.7
Make sure to checkout commit 36e7cff94fbb4af5d8de6739e66164c6e6873586. At this time, checking out 5.7 does exactly that.
Place the contents below in qt5vars.bat located at C:\Qt\qt5
. Make adjustments if you need to:
@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
After that, execute this file and properly initiate the repository:
qt5vars.bat
perl init-repository
Finally, to configure and compile the library successfully (with debug and release versions), make sure the paths referenced by configure
are also valid on your system:
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
Everything so far should have run smoothly and beautifully. Now it's a matter of configuring Qt Creator to detect this new Qt Version and create a new Kit to use on your projects:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With