Question

I wrote a simple HelloWorld console application and compiled it on Windows 7 with MinGW compiler using one of these commands:

gcc -Wall -pedantic Hello.c -o Hello.exe
g++ -Wall -pedantic Hello.cpp -o Hello.exe

However the compiler links some own dynamic libraries into the app and when i copy the executable into another computer with Windows 7, which does not have MinGW installed, i'm getting missing library error. On Linux this problem is solved by package system, which automatically installs all needed libs, but in Windows you surely don't want to tell your users to install MinGW in order to run your program.

So my question is: How do i link all libraries properly and what else do i have to do to make my application run independently?

Although i believe, this must be a fundamental problem to all Windows programmers, i have been unable to find any answers on the internet (maybe i just don't know how and what to search).

Was it helpful?

Solution

It was in the FAQ at some stage, but now I seem to find it only on this page:

Why I get an error about missing libstdc++-6.dll file when running my program?

GCC4 dynamically link to libgcc and libstdc++ libraries by default which means that you need a copy of libgcc_s_dw2-1.dll and libstdc++-6.dll files to run your programs build with the GCC4 version (These files can be found in MinGW\bin directory). To remove these DLL dependencies, statically link the libraries to your application by adding "-static-libgcc -static-libstdc++" to your "Extra linking options" in the project settings.

Try this,

g++ -static-libgcc -static-libstdc++ -Wall -pedantic Hello.cpp -o Hello.exe

OTHER TIPS

I'm afraid to say that with all of the applications installed on my machine, it's easy to identify which ones were built with MinGW. The telltale sign is a folder filled with libraries.

Check to see if the libraries that you need are distributable, and then simply include them in your .exe directory.

Although you may have other applications installed on user's machine, and some of them may contain the libraries that you need, there's a good chance that your application wont be compatible with them. This is why asking your users to install MinGW would be unlikely to work anyways.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top