Remove dependency to LIBWINPTHREAD-1.DLL
-
@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.
" -
wrote on 13 Jan 2016, 11:49 last edited by
I did try that but it didn't work for me.
-
-
-
@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!
@outsider
Ok sorry I couldn't be of more help
and good luck :) -
wrote on 13 Jan 2016, 21:22 last edited by outsider
@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. -
-
Congrats and thank you for posting solution.
-
wrote on 13 Jan 2016, 21:37 last edited by
@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. -
@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.wrote on 23 Jun 2018, 09:33 last edited by@outsider Hi,
I had the same problem (imports from libwinpthread-1.dll in my static Qt application), and I was able to solve it with the following line in the qmake config of qt creator:CONFIG+=static "QMAKE_LFLAGS+=-static -static-libgcc -static-libstdc++ -lstdc++" DEFINES+=STATIC
The important part seems to be the "-static" switch before "-lstdc++"
-
This post is deleted!