Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qt static with OpenSSL issue



  • Hi! I want to build Qt statically with OpenSSL. I have set up the batch file:

    SET /P qtBuildType=Qt build type (shared/static): 
    SET /P qtBuildMySqlIncludePath=MySql include path: 
    SET /P qtBuildMySqlLibPath=MySql lib path: 
    SET /P qtBuildOpenSSLIncludePath=OpenSSL include path: 
    SET /P qtBuildOpenSSLLibPath=OpenSSL lib path: 
    SET /P qtBuildPath=Enter Qt build path: 
    configure.bat -debug-and-release -%qtBuildType% -opensource -nomake tools -nomake examples -no-ltcg -sql-mysql -I "%qtBuildMySqlIncludePath%" -L "%qtBuildMySqlLibPath%" -openssl-linked -I "%qtBuildOpenSSLIncludePath%" -L "%qtBuildOpenSSLLibPath%" -prefix "%qtBuildPath%"
    

    It works well, but then I get issue:

    ..\..\bin\xmlpatterns.exe : fatal error LNK1120: 197 unresolved externals
    jom: D:\QtBuild\Src\qtxmlpatterns\tools\xmlpatterns\Makefile.Release [..\..\bin\xmlpatterns.exe] Error 1120
    jom: D:\QtBuild\Src\qtxmlpatterns\tools\xmlpatterns\Makefile [release] Error 2
    jom: D:\QtBuild\Src\qtxmlpatterns\tools\Makefile [sub-xmlpatterns-make_first] Error 2
    jom: D:\QtBuild\Src\qtxmlpatterns\tools\Makefile [sub-xmlpatternsvalidator-make_first] Error 2
    jom: D:\QtBuild\Src\qtxmlpatterns\Makefile [sub-tools-make_first] Error 2
    jom: D:\QtBuild\Src\Makefile [module-qtxmlpatterns-make_first] Error 2
    

    Screenshot:

    0_1536151471731_2018-09-05_154409.png

    I have tried different OpenSSL versions but the issue still exists. I have found the similar issue here: https://forum.qt.io/topic/85501/error-whie-building-qt-5-9-with-openssl-statically-using-vs2015/8

    But I can't find the patch files. Where can I get the patch? Thank you.


  • Lifetime Qt Champion

    Hi,

    The patch is embedded in the post on that thread.



  • @SGaist

    Hi! So there are no actual patch files, only embedded code in the post? Thanks.


  • Lifetime Qt Champion

    The post contains the patch. Copy the content in a file and then you can apply it.



  • @SGaist

    Ok. I will try the patch and reply later. Thanks.



  • @SGaist

    Hi! I have tried it but I get issue:

    0_1536238582630_2018-09-06_155549.png

    I think there is a syntax error in the file. I will check it.


  • Lifetime Qt Champion

    Did you do the build from a clean state ?

    In anywise, you should use out of source builds, so if something goes wrong, you can juste nuke the folder and start again.



  • @SGaist

    Yes, I have a zip copy and delete old src dir and extract the new every time the build fails. So it is a clean state. I validated json using the https://jsonlint.com service and it displays errors:

    0_1536239353418_2018-09-06_160825.png

    So it contains syntax errors. It's messy to write it all (patch) to config/pri files, better would be replace the files. I will try to fix these errors.



  • Now it fails with the error:

    Info: creating super cache file D:\QtBuild\Src\.qmake.super
    D:/QtBuild/Src/qtbase/mkspecs/features/qt_configure.prf:1941: Error parsing JSON at 411:41: unterminated array
    Project ERROR: Invalid or non-existent file D:/QtBuild/Src/qtbase/src/network/configure.json.
    

    I will disable the xmlpatterns and try again.



  • It fails with another issue:

    0_1536245574428_2018-09-06_175240.png

    I use Win32 OpenSSL v1.0.2p. I will try different version: Win32OpenSSL-1_0_2L.



  • The same issue still exists with Win32OpenSSL-1_0_2L:

    0_1536247176588_2018-09-06_181909.png

    I use Qt 5.9.6. Has anyone build Qt 5.9.6 statically with OpenSSL successfully? I think the problem is with Qt, not the OpenSSL libs. Thanks.



  • I was wrong. I came across this issue: https://bugreports.qt.io/browse/QTBUG-58024
    The problem was with the OpenSSL libs. I have downloaded OpenSSL v1.0.2l (stable) for VS 2017 from the website: https://www.npcglib.org/~stathis/blog/precompiled-openssl/

    Extracted it, and added to the include/libs path in my batch file. Now it compiles without errors:

    SET /P qtBuildType=Qt build type (shared/static): 
    SET /P qtBuildMySqlIncludePath=MySql include path: 
    SET /P qtBuildMySqlLibPath=MySql lib path: 
    SET /P qtBuildOpenSSLIncludePath=OpenSSL include path: 
    SET /P qtBuildOpenSSLLibPath=OpenSSL lib path: 
    SET /P qtBuildPath=Enter Qt build path: 
    configure.bat -debug-and-release -%qtBuildType% -opensource -nomake tools -nomake examples -no-ltcg -sql-mysql -I "%qtBuildMySqlIncludePath%" -L "%qtBuildMySqlLibPath%" -ssl -openssl -openssl-linked -I "%qtBuildOpenSSLIncludePath%" -L "%qtBuildOpenSSLLibPath%" OPENSSL_LIBS="-lUser32 -lAdvapi32 -lGdi32 -lCrypt32" OPENSSL_LIBS_DEBUG="-lssleay32MTd -llibeay32MTd" OPENSSL_LIBS_RELEASE="-lssleay32MT -llibeay32MT" -prefix "%qtBuildPath%"
    

    0_1536253934336_2018-09-06_191732.png



  • @Cobra91151 I followed these steps which lead to a successful compilation. Now, however, my application crashes immediately after launch. Have you seen anything like this? Thanks



  • @Bernard-Lowe

    Hi! What is your compiler? Try to attach the debugger to the application and check again. By the way, check my Qt static with MySQL issue here: https://forum.qt.io/topic/94378/qt-static-with-mysql-issue/33 to get more information about Qt static compilation.



  • @Cobra91151 Hello! Thanks for your comprehensive response. My compiler is VS 2017 (linked with OpenSSL v1.0.2l). I had a debugger attached (cdb.exe) through qtcreator which would detatch the debugger before the main entry point. I am on openssl 'l' so your post could be very relevant here so I'll explore after trying one more thing:
    One major oops that I had just realized was that I left in MD instead of MT after setting -static-runtime in configure so I am trying with MT now.



  • @Bernard-Lowe

    Hi! Try compiling Qt with SSL /MT libs and reply. By the way, you can check if it work with Visual Studio before compiling Qt. By creating simple console project:

    Code:

    #include <iostream>
    #include <openssl/bio.h>
    #include <openssl/ssl.h>
    #include <openssl/err.h>
    using namespace std;
    
    int main()
    {
    	cout << "Hello World!" << endl;
    	SSL_load_error_strings();
    	ERR_load_BIO_strings();
    	OpenSSL_add_all_algorithms();
            system("Pause");
            return 0;
    }
    

    Don't forget to add all the OpenSSL includes/libs to VS 2017 and change Runtime library to Multi-threaded (/MT) (as Release) in Code Generation section.



  • @Cobra91151
    Your spike solution worked perfectly, it was also quite revealing because after succeeding using https://www.npcglib.org/~stathis/blog/precompiled-openssl/ MT libs with static runtime in Visual Studio, I attempted to use the MD libs and the linker attempted to look for a ssleay32MD DLL as if it was a windows system library which was not expected behavior for me.

    My build did not fare as well because I was attempting to use https://slproweb.com/products/Win32OpenSSL.html libraries. I will now try npcg lib with MT and static runtime set. Crossing my fingers.

    Here was my configure command on that last failed build using slproweb libs

    configure -prefix C:\Qt\5.11.2_openssl -mp -debug-and-release -opengl desktop -opensource -static -static-runtime -opensource -confirm-license -no-icu -no-sql-sqlite -no-qml-debug -nomake examples -nomake tests -skip qtactiveqt -skip qtserialport -skip qtquickcontrols -skip qtsensors -skip qtlocation -skip qtscript -platform win32-msvc -openssl-linked -I C:\OpenSSL-Win64\include -L C:\OpenSSL-Win64\lib\VC\static OPENSSL_LIBS_DEBUG="libeay32MTd.lib ssleay32MTd.lib" OPENSSL_LIBS_RELEASE="libeay32MT.lib ssleay32MT.lib"
    


  • Failed on unresolved external errors akin to below:

    libeay32MT.lib(rand_win.obj) : error LNK2019: unresolved external symbol __imp_CreateCompatibleBitmap referenced in function readscreen
    

    It looks like i need to link in GDI as well according to this Stack Overflow post



  • @Bernard-Lowe

    You need to specify additional libs to configure. I have the batch file for Qt compilation. For example, you need:

    Debug: OPENSSL_LIBS="-llibeay32MTd -lssleay32MTd -lUser32 -lAdvapi32 -lGdi32 -lCrypt32"

    Release: OPENSSL_LIBS="-llibeay32MT -lssleay32MT -lUser32 -lAdvapi32 -lGdi32 -lCrypt32"



  • @Cobra91151 Wish that I saw your note earlier. I got it to work using this configure:

    configure -prefix C:\Qt\5.11.2_openssl -mp -debug-and-release -opengl desktop -opensource -static -static-runtime -opensource -confirm-license -no-icu -no-sql-sqlite -no-qml-debug -nomake examples -nomake tests -skip qtactiveqt -skip qtserialport -skip qtquickcontrols -skip qtsensors -skip qtlocation -skip qtscript -platform win32-msvc -openssl-linked -I C:\Development\openssl-1.0.2l-vs2017\include64 -L C:\Development\openssl-1.0.2l-vs2017\lib64 OPENSSL_LIBS_DEBUG="libeay32MTd.lib ssleay32MTd.lib gdi32.lib User32.lib" OPENSSL_LIBS_RELEASE="libeay32MT.lib ssleay32MT.lib gdi32.lib User32.lib"
    


  • @Cobra91151 How did you apply this patch? I'm getting errors


  • Lifetime Qt Champion

    @mcpp what exact errors ? What version of OpenSSL ?



  • @mcpp

    Hi! Please specify what issues with OpenSSL you encountered during Qt static compilation? I will try to help you.



  • This post is deleted!

Log in to reply