Using the C and C++ compiler


The C compiler installed on these systems is the freeware gcc compiler. This compiler differs somewhat from the commercial Sun compiler. The command to run the compiler is:

gcc options... source files...

Where some useful options are:
-o filename
name the output executable filename instead of a.out
-O2
use the maximum optimization level to reduce execution time
-g
include extra debugging symbols to allow the use of gdb or dbx
-Wall
turn on almost all useful warnings; this may catch bugs and portability problems in your code
For example, to compile a file called prog.c, use the command
 gcc -O2 prog.c
which would compile prog.c with the highest level of optimization, and save the result in the executable a.out.

Using C++

Actually, gcc supports both C and C++. If you wish to compile a C++ program, use 'g++' instead of gcc, and use the '.cpp' or '.C' extension instead of the '.c' extension. The same options as above may be used.

Read the man page for gcc and g++ for additional information.

Examine these simple C examples.

Also, these books may be useful: