Remove dependency to LIBWINPTHREAD-1.DLL



  • Hi,
    I built a desktop application for Windows under a commercial license but can't remove dependency to LIBWINPTHREAD-1.DLL

    I first built a static Qt 5.4.2 .
    Then I removed dependency to LIBGCC_S_DW2-1.DLL and LIBSTDC++-6.DLL by adding in my .PRO file:
    CONFIG += static
    QMAKE_LFLAGS += -static-libgcc -static-libstdc++

    Now I'm only left with the .EXE and LIBWINPTHREAD-1.DLL (the app runs OK with these two).
    I tried replacing the previous line with:
    QMAKE_LFLAGS += -static-libgcc -static-libstdc++ -Wl,-Bstatic -lwinpthread
    and rebuild, but that still doesn't remove the dependency.

    Any ideas?
    Thanks


  • Qt Champions 2016

    Hi and welcome
    this is with mingw compiler ?



  • @mrjj Yes it is !


  • Qt Champions 2016

    @outsider
    hi
    I assume you saw this
    http://stackoverflow.com/questions/13768515/how-to-do-static-linking-of-libwinpthread-1-dll-in-mingw
    did u try with -lstdc++ as it seems to work for him
    "
    -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic
    Notice the -lstdc++ before -lpthread. It worked for me.
    "



  • I did try that but it didn't work for me.


  • Qt Champions 2016

    @outsider @outsider
    Ok. damn :)
    Googling it a bit it seems
    that default its not possible with the mingw version that comes with Qt.
    At least I could not get it to work either.

    Is it 64 bit?

    Since you have commercial support, you could call them and ask?



  • @mrjj I am rebuilding Qt now, making sure that the same mingw was used for building static Qt and static app... I'll get back with an answer after that and will try to call support too. Thanks!


  • Qt Champions 2016

    @outsider
    Ok sorry I couldn't be of more help
    and good luck :)



  • @mrjj I got it to work:

    • I build my project normally from Qt IDE with :
      CONFIG += static
      QMAKE_LFLAGS += -static-libgcc -static-libstdc++

    • This creates a binary name.exe still dependent on libwinpthread-1.dll
      (IMPORTANT: If you test it on the same computer, it might work, because your environment PATH contains the DLL, but it won't work on another computer.)

    • Now I checked the last g++ command in Compile Output (bottom line in Qt IDE). This is what I got (you might get something different depending on the project options - JUST COPY THE COMMAND YOU HAVE):

    g++ -static-libgcc -static-libstdc++ -Wl,-s -Wl,-subsystem,windows -mthreads -o release\name.exe object_script.name.Release -lmingw32 -LC:/Qt/542static/qtbase/lib -lqtmain -lQt5OpenGL -lQt5Widgets -LC:/Qt/542static/qtbase/plugins/platforms -lqwindows -lwinspool -lshlwapi -lQt5PlatformSupport -LC:/Qt/542static/qtbase/plugins/imageformats -lqdds -lqicns -lqico -lqjp2 -lqmng -lqtga -lqtiff -lqwbmp -lqwebp -lQt5Gui -lcomdlg32 -loleaut32 -limm32 -lwinmm -lglu32 -lopengl32 -lgdi32 -lqtharfbuzzng -lQt5Core -lole32 -luuid -lws2_32 -ladvapi32 -lshell32 -luser32 -lkernel32 -lmpr -lz

    • I launched the command prompt : Start>Run>cmd.exe

    • Changed the directory to build-name-542_static-Release (where the Makefile is)

    • I copied the final line into the command prompt and AT THE END I ADDED the static libraries directly by name:
      -l:libwinpthread.a

    • So my command was now :

    g++ -static-libgcc -static-libstdc++ -Wl,-s -Wl,-subsystem,windows -mthreads -o release\name.exe object_script.name.Release -lmingw32 -LC:/Qt/542static/qtbase/lib -lqtmain -lQt5OpenGL -lQt5Widgets -LC:/Qt/542static/qtbase/plugins/platforms -lqwindows -lwinspool -lshlwapi -lQt5PlatformSupport -LC:/Qt/542static/qtbase/plugins/imageformats -lqdds -lqicns -lqico -lqjp2 -lqmng -lqtga -lqtiff -lqwbmp -lqwebp -lQt5Gui -lcomdlg32 -loleaut32 -limm32 -lwinmm -lglu32 -lopengl32 -lgdi32 -lqtharfbuzzng -lQt5Core -lole32 -luuid -lws2_32 -ladvapi32 -lshell32 -luser32 -lkernel32 -lmpr -lz -l:libwinpthread.a

    • You will notice the name.exe getting a bit bigger and things are ok now. I tested it on another computer without Qt or any programming environment and it worked.

    I also tried to do it this way QMAKE_LFLAGS += -static-libgcc -static-libstdc++ -l:libwinpthread.a
    but that doesn't work, I think it's because the .a is not added at the end in the g++ command line
    So yeah it's a bit complicated but it can be done.
    If anyone finds a simpler alternative feel free to let us know.


  • Qt Champions 2016

    Congrats and thank you for posting solution.



  • @mrjj Thanks :)

    Apparently QMAKE_LFLAGS lacks the option to add something at the end in that last link command.
    On various sites people kept saying that the static libraries should be added at the end - but I don't know if it can be done directly from the .pro file.


Log in to reply
 

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