===== Using the GNU C++ Compiler =====
==== Overview ====
[[ http://directory.fsf.org/devel/compilers/gcc.html | The GNU Compiler Collection ]] (GCC) is an integrated collection of compilers for several languages, including C, C++, Java and Fortran.
Our interest here is with the [[ http://directory.fsf.org/gpp.html | C/C++ compiler ]].
==== Syntax ====
The g++ command has the following syntax:
| **g++** [**-**//option...//] //file//... [//option// | //file//]... |
where //option// denotes an option or switch (see below) and //file// denotes a file name.
==== Options ====
The list of valid options/switches for the g++ command includes the following:
^Option^Purpose^
|c|Compiles without linking|
|D//name//=//definition//|Defines a symbol (as with ''%%#define%%'')|
|E|Stop after the preprocessing stage|
|g|Produce debugging information|
|I|Searches the given directory for "includes"|
|l//libname//|Searches the specified library when linking|
|o//filename//|Names the output file|
|M|Instead of preprocessing, output a rule suitable for use by ''%%make%%''|
|-help|Provides (some) help|
|-version|Displays the version number|
==== Examples ====
The following command compiles (but does not link) the C source file named ''%%test.c%%'' and creates the file ''%%test.o%%'':
g++ -c test.c
The following command first defines the symbol ''%%DEBUG%%'' in the C++ source file named ''%%Demo.cpp%%'' and then compiles and links it (creating an executable file named ''%%Demo%%'').
g++ -DDEBUG=VERBOSE Demo.cpp -o Demo
The following command "includes" files from the directory ''%%/myfiles/include%%'' in addition to the standard INCLUDE directory.
g++ -I/myfiles/include Demo.cpp -o Demo
The following commands first compile the source files for a small application (written in C) and then links them into an executable named ''%%example%%''.
g++ -c account.c
g++ -c example.c
g++ example.o account.o -o example
==== Error and Warning Messages ====
Error and warning messages generated by the GCC are often less than clear. There are several places you can go for help, including:
* [[ http://www.network-theory.co.uk/docs/gccintro/gccintro_94.html |
Compiler Error Messages ]] (courtesy of Network Theory, Ltd.)
* [[ http://users.csc.calpoly.edu/~jdalbey/101/Resources/errormessages.html |
Common Error Messages ]] (courtesy of California Polytechnic State University)