Static build of Qt Qt5Network linking error
Asked Answered
D

5

11

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.

Dispersoid answered 31/5, 2015 at 10:3 Comment(10)
Might well be a Qt bug, then it would be worth to report it in Qt JIRA. When saying "Qt 5.4", do you mean 5.4.0 or 5.4.1?Nupercaine
@FrankOsterfeld Thank you, I have reported it as a bug. bugreports.qt.io/browse/QTBUG-46405 I have meant 5.4.1, sorry for the inaccuracy.Dispersoid
@FrankOsterfeld I got the answer that this is not a bug, but personally I did not completly ruled it ou yet. Could you suggest a version of Qt for trying?Dispersoid
" do not find the ssl or the crypto libraries in the OpenSSL build I compiled" Well, fix this first, your problem has nothing to do with Qt then.Crissycrist
@KubaOber Well that's easier said then done. I have downloaded the official binary distribution of OpenSSL for Windows, and it does not contain it. I don't know what I could do about that.Dispersoid
@GáborAngyal Then build it yourself, or download the unofficial binary build from shining light productions. I've been doing that for years now, and it works.Crissycrist
@KubaOber Which version of OpenSSL an Qt are you using?Dispersoid
@GáborAngyal 5.2.x, most recent OpenSSL from shining light.Crissycrist
@KubaOber I have tried and was able to build that. But Qt 5.2 only supports msvc2012, which does not support all the new c++11 and c++14 features I use :(Dispersoid
@GáborAngyal Hey! Since this question wasn't answered in +2 years I added all the nasty details needed to compile a static version of Qt 5.7.1 on Windows (MSVC2013) with SSL and MySQL support. I know your question is old but make sure to check it out anyway. This question remains relevant and continues to receive visitors redirected by Google.Uitlander
U
2

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:

Uitlander answered 30/6, 2017 at 16:24 Comment(0)
I
0

I somehow made it to work quite fast with Qt 5.3 some time ago:

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 points to -MT compiler option makespec so the app also uses MT. Also to make it all working in the app .pro file:

LIBS += -L$$PWD/../third-party/openssl/lib -llibeay32MT
LIBS += -L$$PWD/../third-party/openssl/lib -lssleay32MT

Be sure to reinstall entire Qt Src directory in between of static Qt build attempts, from my observation there always hard to track leftovers that break everything on the new run.

And OPENSSL_HOME variable set to ProjectDir\third-party\openssl

Irradiant answered 18/6, 2015 at 4:8 Comment(0)
W
0

I have just spent about a day dealing with that static build, and what work for me is:

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

Also, you must notice that I used openssl-1.0.1r, beacuse new version build algorithm and .dll names differ form one in the instuctions, so the instruction alghorithm does not work with them, openssl-1.0.1r is not deprecated, so it is ok.

Also I had problems with the building.bat script, so here the one which worked for me in a propper way:

   ..\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"

Notice, that my "Build" dir was out of "qt-5.8.0" dir, so please, correct the path ..\qt-5.8.0\configure to fit your filestucture. All other step were made deffenitely as it is said in the instruction under a link.

Wright answered 15/4, 2017 at 23:15 Comment(0)
A
0

This is an old question but i would give a reply this is dependent on the version of open ssl. If you are using a version below 1.1.0, the above sequence may be ok, however using 1.1.1 from my experience it does not need the OPENSSL_LIBS="-LC:\OpenSSL-Win32\lib -lssl -lcrypto". When configured, there is an item called QtNetowrk and it shows if the openssl library has been detected. The following works with 1.1.1 static and 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
Ascarid answered 27/6, 2019 at 18:57 Comment(0)
W
-1

I ran into the same problem and i think the problem is that we build without ssl first and the src/network/Makefiles are not regenerated

When I deleted them and ran configure again I got through

Hope This Helps

Wireless answered 14/12, 2017 at 19:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.