MinGW .exe requires a few gcc dll’s regardless of the code?

Your commands are wrong !

Go to the directory where your main.cpp file is, and try the following.

g++.exe -Wall -c -g main.cpp -o obj\Debug\main.o
g++.exe -static -static-libgcc -static-libstdc++ -o "bin\Debug\Hello World.exe" obj\Debug\main.o

then you’ll no longer need to copy the DLLs (for your Hello World program).

Other notes:

The MinGW installation instructions recommends setting

c:\minGW;c:\MinGW\bin;

to the PATH environment variable.

Normally the

-static -static-libgcc -static-libstdc++

linker options should work (try all 3 of them at once). But not for libwinpthread-1.dll.

Also, try to clean before recompiling.

There’s no “-static-something” command.

Only standard libraries libgcc and libstdc++ can be set to static linking.

For other libraries, you first switch to static linking with “-static” and then list the libraries to include with separate commands, i.e. “-lpthread”.

Cmake users should try adding:

set(CMAKE_CXX_STANDARD_LIBRARIES "-static-libgcc -static-libstdc++ -lwsock32 -lws2_32 ${CMAKE_CXX_STANDARD_LIBRARIES}")

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive")

Leave a Comment