Building Qt5 with OpenSSL support using VS 2015



  • I'm looking for some guidance on building Qt5 with OpenSSL support using VS 2015
    I've read through a number of older posting on this forum and elsewhere. I am looking for a more recently shared experience(s).

    older posts:

    http://xpam.pl/blog/?p=106

    http://www.qtcentre.org/threads/30523-How-to-Building-Qt-with-OpenSSL-support-using-the-Windows-SDK

    https://stackoverflow.com/questions/24261974/how-to-build-qt5-with-openssl-support



  • Hi,
    I just build Qt from source with the instructions found here:
    http://doc.qt.io/qt-5/windows-building.html
    http://doc.qt.io/qt-5/windows-requirements.html
    The build succeeded without a single snatch, surprisingly... I work on Windows7 with MSVS2015 Community Edition installed. This build was without the -openssl-link configure option however.

    It seems that before you configure and start your Qt build, you need to build OpenSSL with the instructions from here (there are even batch files provided for build with MSVS2015):
    building_openssl_with_visual_studio_2013
    If you don't want to build, the above site also provides precompiled binaries for MSVS2015 as well!

    Then, this doc tells how you can statically link your Qt Build to the OpenSSL libraries you built above:
    http://doc.qt.io/qt-5/ssl.html

    The instructions seem clear. What have you tried so far?

    PS. The contents of my qt5vars.cmd batch file is as follows:

    REM Set up \Microsoft Visual Studio 2013, where <arch> is \c amd64, \c x86, etc.
    CALL "D:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
    SET _ROOT=E:\Qt-Debug
    SET PATH=%_ROOT%\qtbase\bin;%_ROOT%\gnuwin32\bin;%PATH%
    REM Uncomment the below line when using a git checkout of the source repository
    REM SET PATH=%_ROOT%\qtrepotools\bin;%PATH%
    SET PATH=E:\Qt\Tools\QtCreator\bin;%PATH%
    SET _ROOT=
    

    Up there, I used the amd64 architecture and the same path .bat path I use in my Qt Creator's MSVC2015 kit settings.

    The directory E:\Qt-Debug is the directory where I copied the Qt source from my Qt installation (originally in the \Src subdirectory), i.e. the path of the configure script.

    Then, since Qt Creator comes with the jom.exe tool build tool, I added the path to it to the PATH variable so that I can build with jom instead of nmake by simply typing jom at the command line.



  • I'm following these directions but running into corecrt.h not found after configure. Tried explicitly specifying include path for corecrt.h header file but still getting the same error

    OS: Windows 7 64-bit.
    Visual Studio 2015 Update 3
    Installed 2 versions of Windows 10 SDK but the latest version in Visual Studio Modify screen fails to install - tried several times.

    configure -commercial -static -debug-and-release -prefix C:\Qt\Static\5.12.0 -platform win32-msvc2015 -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -opengl desktop -sql-odbc -sql-sqlite -make libs -nomake tools -nomake examples -nomake tests -openssl-linked OPENSSL_LIBS="-llibssl -llibcrypto" -I C:\openssl\include\openssl -L C:\openssl\lib -I "C:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\ucrt" -L "C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10586.0\ucrt\x86"

            cl -c -Fo./ -Fdqmake.pdb  -W2 -nologo -O1  /MP /wd4577   -IC:\Qt\Static\
    qt-everywhere-src-5.12.0\qtbase\qmake -IC:\Qt\Static\qt-everywhere-src-5.12.0\qt
    base\qmake\library -IC:\Qt\Static\qt-everywhere-src-5.12.0\qtbase\qmake\generato
    rs -IC:\Qt\Static\qt-everywhere-src-5.12.0\qtbase\qmake\generators\unix -IC:\Qt\
    Static\qt-everywhere-src-5.12.0\qtbase\qmake\generators\win32 -IC:\Qt\Static\qt-
    everywhere-src-5.12.0\qtbase\qmake\generators\mac  -IC:\Qt\Static\qt-everywhere-
    src-5.12.0\qtbase/include -IC:\Qt\Static\qt-everywhere-src-5.12.0\qtbase/include
    \QtCore -IC:\Qt\Static\qt-everywhere-src-5.12.0\qtbase/include\QtCore\5.12.0 -IC
    :\Qt\Static\qt-everywhere-src-5.12.0\qtbase/include\QtCore\5.12.0\QtCore  -I..\s
    rc\corelib\global  -IC:\Qt\Static\qt-everywhere-src-5.12.0\qtbase\mkspecs\win32-
    msvc   -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS  -DQT_VERSION_STR=\"5
    .12.0\" -DQT_VERSION_MAJOR=5 -DQT_VERSION_MINOR=12 -DQT_VERSION_PATCH=0  -DQT_BU
    ILD_QMAKE -DQT_BOOTSTRAPPED -DPROEVALUATOR_FULL  -DQT_NO_FOREACH -DUNICODE -D_EN
    ABLE_EXTENDED_ALIGNED_STORAGE -c -Yc -Fpqmake_pch.pch -TP C:\Qt\Static\qt-everyw
    here-src-5.12.0\qtbase\qmake\qmake_pch.h
    qmake_pch.h
    C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\crtdefs.h(10): fa
    tal error C1083: Cannot open include file: 'corecrt.h': No such file or director
    y
    jom: C:\Qt\Static\qt-everywhere-src-5.12.0\qtbase\qmake\Makefile [qmake_pch.obj]
     Error 2
    

  • Qt Champions 2018

    @Taytoo said in Building Qt5 with OpenSSL support using VS 2015:

    -L "C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10586.0\ucrt\x86"

    This doesn't look correct.
    And if you open the VisualStudio Command prompt then those two includes should be automatically added to the compiler - no need to specify them during qt configuration.



  • @Christian-Ehrlicher The problem is VS path points to SDK version: 10.0.14393.0 - which although recent than the one above, does Not have UCRT folder so that's why include isn't working.

    I found a solution here: https://bugreports.qt.io/browse/QTBUG-50191?focusedCommentId=318801&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-318801

    but its more of a hack and I'm tyring to fix it properly.


  • Qt Champions 2018


  • Lifetime Qt Champion

    Hi

    @Christian-Ehrlicher configure accepts -L and -I with a space unlike the linker and compiler options.


  • Qt Champions 2018

    @Taytoo said in Building Qt5 with OpenSSL support using VS 2015:

    C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10586.0\ucrt\x86

    @SGaist: but this is an include folder. And in this folder there is the corecrt.h header file ...



  • Removed VS2015 including all Windows SDKs, Installed VS2017 and its working now.

    New issue while running jom.Not sure whats it complaining about?

            cl -c -FIqt_gui_pch.h -Yuqt_gui_pch.h -Fp.pch\release\Qt5Gui_pch.pch -nologo -Zc:wchar_t -FS -Zc:rvalueCast
     -Zc:inline -Zc:strictStrqgenericmatrix.obj : warning LNK4221: This object file does not define any previously unde
    fined public symbols, so it will not be used by any link operation that consumes this library
    qabstractlayoutstyleinfo.obj : warning LNK4221: This object file does not define any previously undefined public sy
    mbols, so it will not be used by any link operation that consumes this library
    qfragmentmap.obj : warning LNK4221: This object file does not define any previously undefined public symbols, so it
     will not be used by any link operation that consumes this library
    jom: C:\Qt\Static\5.12.0\qtbase\Makefile [sub-src-make_first] Error 2
    jom: C:\Qt\Static\5.12.0\Makefile [module-qtbase-make_first] Error 2
    

  • Lifetime Qt Champion

    @Christian-Ehrlicher said in Building Qt5 with OpenSSL support using VS 2015:

    @Taytoo said in Building Qt5 with OpenSSL support using VS 2015:

    C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10586.0\ucrt\x86

    @SGaist: but this is an include folder. And in this folder there is the corecrt.h header file ...

    Correct, I misread the path !


  • Qt Champions 2018

    @Taytoo Did you try a complete rebuild? Delete build directory and start from scratch.



  • @jsulm tried it, no luck. This Static building thing is really getting tiring now, its been 2 days that I've been trying to get it to work. Would be nice if Qt had some tool to check for pre-requisities, paths, directories etc. Because the errors themselves are very non-descriptive so you just have to google and try to figure out what's causing failures.

    E.g. Currently, I'm trying building in the sources folder and now i"m getting unresolved external symbols related to openssl. I checked several examples and my configure options are correct, openssl static lib is present in the correct folder, tried downloading pre-built openssl lib as well as generating my own lib, still getting the same openssl error.

    Qt version: 5.12.0
    MSVC2017
    Openssl 1.1.1a

    configure.bat -commercial -static -debug-and-release -prefix C:\Qt\Static\5.12.0 -platform win32-msvc2017 -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -opengl desktop -sql-odbc -sql-sqlite -make libs -nomake tools -nomake examples -nomake tests OPENSSL_LIBS="-llibssl -llibcrypto" -openssl-linked -I c:/openssl/build32/include -L c:/openssl/build32/lib
    
    Qt5Network.lib(qsslsocket_openssl_symbols.obj) : error LNK2019: unresolved external symbol _DSA_new referenced in functi
    on "struct dsa_st * __cdecl q_DSA_new(void)" (?q_DSA_new@@YAPAUdsa_st@@XZ)
    Qt5Network.lib(qsslsocket_openssl_symbols.obj) : error LNK2019: unresolved external symbol _DSA_free referenced in funct
    ion "void __cdecl q_DSA_free(struct dsa_st *)" (?q_DSA_free@@YAXPAUdsa_st@@@Z)
    Qt5Network.lib(qsslsocket_openssl_symbols.obj) : error LNK2019: unresolved external symbol _DSA_bits referenced in funct
    ion "int __cdecl q_DSA_bits(struct dsa_st *)" (?q_DSA_bits@@YAHPAUdsa_st@@@Z)
    Qt5Network.lib(qsslsocket_openssl_symbols.obj) : error LNK2019: unresolved external symbol _RSA_new referenced in functi
    on "struct rsa_st * __cdecl q_RSA_new(void)" (?q_RSA_new@@YAPAUrsa_st@@XZ)
    Qt5Network.lib(qsslsocket_openssl_symbols.obj) : error LNK2019: unresolved external symbol _RSA_bits referenced in funct
    ion "int __cdecl q_RSA_bits(struct rsa_st *)" (?q_RSA_bits@@YAHPAUrsa_st@@@Z)
    Qt5Network.lib(qsslsocket_openssl_symbols.obj) : error LNK2019: unresolved external symbol _RSA_free referenced in funct
    ion "void __cdecl q_RSA_free(struct rsa_st *)" (?q_RSA_free@@YAXPAUrsa_st@@@Z)
    Qt5Network.lib(qsslsocket_openssl_symbols.obj) : error LNK2019: unresolved external symbol _DH_new referenced in functio
    n "struct dh_st * __cdecl q_DH_new(void)" (?q_DH_new@@YAPAUdh_st@@XZ)
    Qt5Network.lib(qsslsocket_openssl_symbols.obj) : error LNK2019: unresolved external symbol _DH_free referenced in functi
    on "void __cdecl q_DH_free(struct dh_st *)" (?q_DH_free@@YAXPAUdh_st@@@Z)
    Qt5Network.lib(qsslsocket_openssl_symbols.obj) : error LNK2019: unresolved external symbol _DH_bits referenced in functi
    on "int __cdecl q_DH_bits(struct dh_st *)" (?q_DH_bits@@YAHPAUdh_st@@@Z)
    Qt5Network.lib(qsslsocket_openssl_symbols.obj) : error LNK2019: unresolved external symbol _DH_check referenced in funct
    ion "int __cdecl q_DH_check(struct dh_st *,int *)" (?q_DH_check@@YAHPAUdh_st@@PAH@Z)
    Qt5Network.lib(qsslsocket_openssl_symbols.obj) : error LNK2019: unresolved external symbol _d2i_DHparams referenced in f
    unction "struct dh_st * __cdecl q_d2i_DHparams(struct dh_st * *,unsigned char const * *,long)" (?q_d2i_DHparams@@YAPAUdh
    _st@@PAPAU1@PAPBEJ@Z)
    Qt5Network.lib(qsslsocket_openssl_symbols.obj) : error LNK2019: unresolved external symbol _i2d_DHparams referenced in f
    unction "int __cdecl q_i2d_DHparams(struct dh_st *,unsigned char * *)" (?q_i2d_DHparams@@YAHPAUdh_st@@PAPAE@Z)
    Qt5Network.lib(qsslsocket_openssl_symbols.obj) : error LNK2019: unresolved external symbol _DH_get0_pqg referenced in fu
    nction "void __cdecl q_DH_get0_pqg(struct dh_st const *,struct bignum_st const * *,struct bignum_st const * *,struct big
    num_st const * *)" (?q_DH_get0_pqg@@YAXPBUdh_st@@PAPBUbignum_st@@11@Z)
    ..\..\..\bin\canbusutil.exe : fatal error LNK1120: 244 unresolved externals
    jom: C:\Qt\Static\qt-everywhere-src-5.12.0\qtserialbus\src\tools\canbusutil\Makefile.Release [..\..\..\bin\canbusutil.ex
    e] Error 1120
    jom: C:\Qt\Static\qt-everywhere-src-5.12.0\qtserialbus\src\tools\canbusutil\Makefile [release] Error 2
    jom: C:\Qt\Static\qt-everywhere-src-5.12.0\qtserialbus\src\tools\Makefile [sub-canbusutil-make_first] Error 2
    jom: C:\Qt\Static\qt-everywhere-src-5.12.0\qtserialbus\src\Makefile [sub-tools-make_first] Error 2
    jom: C:\Qt\Static\qt-everywhere-src-5.12.0\qtserialbus\Makefile [sub-src-make_first] Error 2
    jom: C:\Qt\Static\qt-everywhere-src-5.12.0\Makefile [module-qtserialbus-make_first] Error 2
    

  • Qt Champions 2018

    Are you building for 64 or 32 bit target architecture?
    And since you've a commercial license you could ask the Qt Company for help.



  • @Christian-Ehrlicher said in Building Qt5 with OpenSSL support using VS 2015:

    Are you building for 64 or 32 bit target architecture?
    And since you've a commercial license you could ask the Qt Company for help.

    32-bit.

    I'm currently evaluating QT for our commercial software, thought the setup would be straightforward but keep running into one issue after another, so treating it as learning process - still frustrating though.


  • Qt Champions 2018

    Can you show us the link line of Qt5Network.lib? Must be directly above the linker errors.



  • Finally, got it working! Re-set everything again, unzipped fresh sources etc and used this configure...

    configure -commercial -static -debug-and-release -prefix C:\Qt\Static\5.12.0 -platform win32-msvc2017 -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -opengl desktop -sql-odbc -sql-sqlite -make libs -nomake tools -nomake examples -nomake tests -openssl-linked OPENSSL_LIBS="-llibssl -llibcrypto" -I c:\openssl\build32\include -L c:\openssl\build32\lib
    

    not sure if moving openssl-linked ahead made any difference, but I'll just save these settings and stick with them.

    Now, how do I update my Visual studio project to link QT statically?



  • Still working on the static environment setup, getting whole bunch of unresolved external errors. The build config is Win32, which is inline with static qt win32 build. also double checked and QT libs are added as Additional libraries in project settings.

    In the image below, first two errors are related to an internal lib. The remaining errors are all unresolved externals. I did go through an interesting checklist here (https://heejune.me/2015/12/03/resolving-the-lnk2019-error-while-link-qt-app/) and don't see anything that applies to my config.
    0_1548842162714_unresolved.JPG


  • Lifetime Qt Champion

    Hi,

    Might be a silly question but why are you using the VS2017 mkspec for VS2015 ?



  • @SGaist I moved to VS17 because I was getting corecrt errors while building QT.

    Two unresolved errors were solved by adding ws2_32.lib. Also, went into Qt Project Settings - Qt Modules and checked a whole bunch of modules. Now I'm getting only one linker error. Maybe its related to the two E2512 errors?

    0_1548902195774_unresolved2.JPG



  • I've managed to fix the preprocessor error but still not able to figure out linker error. Weird thing is that I've tried compiling my app by linking dynamically with QT (default config) and even that is giving out the same error, so its probably not something specific to static linking with QT.

    Last time my project was compiling successfully in VS2015 against qt dlls. Uninstalled VS2015, installed VS2017 and now seeing this linker error. Any tips?



  • Fixed my compilation issue and also Found a Bug in Qt.

    Repro: In Visual Studio. Go to Qt VS Tools -> Qt Project Settings -> Qt Modules (Tab) and make changes. This will add

    \
    $(INHERIT)\
    

    into the project's Linker -> Additional Dependencies. Removing the slashes solved the problem. No wonder I couldn't figure out what the object file was when I was getting ".obj" error during compilation.



  •         cd examples\ && ( if not exist Makefile C:\Qt\Static\qt-everywhere-src-5.12.0\qtbase\bin\qmake.exe -o Makefile C
    :\Qt\Static\qt-everywhere-src-5.12.0\qtnetworkauth\examples\examples.pro ) && "C:\Program Files (x86)\Microsoft Visual S
    tudio\2017\Professional\VC\Tools\MSVC\14.16.27023\bin\HostX86\x86\nmake.exe" -f Makefile distclean
    ASSERT: "fileName.isEmpty() || isAbsolutePath(fileName)" in file C:\Qt\Static\qt-everywhere-src-5.12.0\qtbase\qmake\libr
    ary\ioutils.cpp, line 53
    NMAKE : fatal error U1077: 'cd' : return code '0x40000015'
    Stop.
    NMAKE : fatal error U1077: 'cd' : return code '0x2'
    Stop.
    

    When I run nmake distclean in sources folder, its keeps running for a while and eventually ends with this error. I built Qt with "nomake examples" flag, is that the reason? Do I need to unzip fresh sources again or can I just ignore this and continue by calling configure and jom?


  • Lifetime Qt Champion

    No, examples are just normal projects. You can open them in Qt Creator and build them from there.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.