Which MinGW file to use as a C++ compiler

Abbas picture Abbas · Feb 19, 2011 · Viewed 11.9k times · Source

I have just installed MinGW and in the bin folder I can see 7 .exe files that compile my program:

  1. c++.exe
  2. g++.exe
  3. mingw32-c++.exe
  4. mingw32-g++.exe
  5. gcc.exe
  6. mingw32-gcc.exe
  7. mingw32-gcc-4.4.1.exe

My small program (testprog.cpp) compiles correctly with each of them; the a.exe file is generated in the bin folder and it runs correctly.

What's the difference between them and which one should I use? Also, what can I do to change the name of the output file from a.exe to testprog.exe automatically upon each successful compile?

Answer

Erik picture Erik · Feb 19, 2011

These follow gcc naming conventions.

  • c++.exe is a traditional name for the system c++ compiler
  • g++.exe and gcc.exe are the names for the gcc compilers that compile for the "current system"
  • mingw32-* versions are the names for the compilers that cross-compile to the "mingw" target. In this case this is the same as the system target.
  • An then mingw32-gcc-4.1.exe is "gcc for mingw target version 4.1"

You should typically compile C code with a "gcc" variant, and c++ code with a "g++" variant.

Use -o filename in order to specify the output filename, the default is a.exe