RUNNING THE GNU OR MICROSOFT COMPILERS
The command used to run the C++(www.cppentry.com) compiler varies across compilers and operating systems. Themost common compilers are the GNU compiler and the MicrosoftVisual Studio compilers. By default, the command to run the GNU compiler is g++:
- $ g++ -o prog1 prog1.cc
Here $ is the systemprompt. The -o prog1 is an argument to the compiler and names the file in which to put the executable file. This command generates an executable file named prog1 or prog1.exe, depending on the operating system. On UNIX, executable files have no suffix; on Windows, the suffix is .exe. If the -o prog1 is omitted, the compiler generates an executable named a.out on UNIX systems and a.exe on Windows. (Note: Depending on the release of the GNU compiler you are using, you may need to specify -std=c++0x to turn on C++(www.cppentry.com) 11 support.)
The command to run theMicrosoft Visual Studio 2010 compiler is cl:
C:\Users\me\Programs> cl /EHsc prog1.cpp
Here C:\Users\me\Programs> is the system prompt and \Users\me\
- C:\Users\me\Programs> cl /EHsc prog1.cpp
Programs is the name of the current directory (aka the current folder). The cl command invokes the compiler, and /EHsc is the compiler option that turns on standard exception handling. TheMicrosoft compiler automatically generates an executable with a name that corresponds to the first source file name. The executable has the suffix .exe and the same name as the source file name. In this case, the executable is named prog1.exe.
Compilers usually include options to generate warnings about problematic constructs. It is usually a good idea to use these options. Our preference is to use -Wall with the GNU compiler, and to use /W4 with the Microsoft compilers.
For further information consult your compiler’s user’s guide.