Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which MinGW file to use as a C++ compiler

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?

like image 608
Abbas Avatar asked Feb 18 '11 23:02

Abbas


People also ask

Can we use MinGW for C?

Log in to your regular user account. Download this MinGW folder and run it. Your browser may warn that "This file is not commonly downloaded and may harm your computer" , but run it anyway.

What compiler should I use for C?

The compiler that we recommend is the GNU Compiler collection or GCC. This is a widely used cross-platform compiler toolsuite that has libraries and compilers for C, C++, Fortran, Java, and more. Additionally the compiler that we will use later on in the course for compiling C code to run on the PIC32 is based on GCC.


3 Answers

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

like image 144
Erik Avatar answered Sep 29 '22 22:09

Erik


It's quite possible that they are all the same; either exact copies or symbolic links to one another. Try using the --version flag on each to see what you've got. On my MingGW installation here, each of those binaries differs (checked with diff), but they all output the same version information (with the exception of the first bit, which is the filename):

gcc.exe (GCC) 3.4.5 (mingw-vista special r3)
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Use the -o flag to change the output file name:

gcc -o testprog.exe testprog.cpp
like image 28
Carl Norum Avatar answered Sep 29 '22 21:09

Carl Norum


In unix they'd mostly by symbolic links. The only major difference is between the 'cc' vs. '++' ones. You should notice a difference between these two if you use any part of the standard C++ library. The '++' versions link to that lib automatically. The 'cc' ones are C compilers and so don't...though you can use them as C++ compilers by just adding -lstdc++ or whatever.

like image 4
Edward Strange Avatar answered Sep 29 '22 23:09

Edward Strange