Static linking with libwinpthread

niXman picture niXman · Feb 2, 2013 · Viewed 9k times · Source

I try to build program with static linked toolchain libraries. I pass:

LDFLAGS="-Wl,-Bstatic -lwinpthread -Wl,-Bdynamic -static-libgcc -static-libstdc++"

but program linked with shared libwinpthread-1.dll.

What I doing wrong?

Only way when I got static linked libwinpthreads is pass -static to LDFLAGS. But it break build programs with plugin system.

I use mingw-w64 + GCC-4.7.2 from the MinGW-builds project: http://sourceforge.net/projects/mingwbuilds/

Answer

Star Brilliant picture Star Brilliant · Jan 17, 2015

Try this:

-static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic

Notice the -lstdc++ before -lpthread. It worked for me.

Make sure to add this to the very end of your g++ command line.