GCC

Use Cases

The simplest use case of the gcc is to compile a single source file and create an executable:

gcc <main source file> -o <executable name>

The usage of the gcc to separately compile several modules and produce an optimized executable is:

gcc -O -c <source file 1> [-o <object file 1]>
gcc -O -c <source file 2> [-o <object file 2]>
...
gcc -O <main source file> <object file 1> <object file 2> ... -o <executable name>

And the usage of the gcc to separately compile several modules, create an archive and produce an optimized executable is:

gcc -O -c <source file 1> -o <object file 1>
gcc -O -c <source file 2> -o <object file 2>
...
ar -crs libname.a <object file 1> <object file 2> ...
gcc -O <main source file> -L. -lname -o <executable name>

The same applies for the c++ (or g++) compiler.

gcc | | ar and nm

Options: