- publishing free software manuals
An Introduction to GCC - for the GNU compilers gcc and g++
by Brian J. Gough, foreword by Richard M. Stallman
Paperback (6"x9"), 144 pages
ISBN 0954161793
RRP £12.95 ($19.95)

"A wonderfully thorough guide... well-written, seriously usable information" --- Linux User and Developer Magazine (Issue 40, June 2004) Get a printed copy>>>

2.4.1 Creating object files from source files

The command-line option -c is used to compile a source file to an object file. For example, the following command will compile the source file ‘main.c’ to an object file:

$ gcc -Wall -c main.c

This produces an object file ‘main.o’ containing the machine code for the main function. It contains a reference to the external function hello, but the corresponding memory address is left undefined in the object file at this stage (it will be filled in later by linking).

The corresponding command for compiling the hello function in the source file ‘hello_fn.c’ is:

$ gcc -Wall -c hello_fn.c

This produces the object file ‘hello_fn.o’.

Note that there is no need to use the option -o to specify the name of the output file in this case. When compiling with -c the compiler automatically creates an object file whose name is the same as the source file, but with ‘.o’ instead of the original extension.

There is no need to put the header file ‘hello.h’ on the command line, since it is automatically included by the #include statements in ‘main.c’ and ‘hello_fn.c’.

ISBN 0954161793An Introduction to GCC - for the GNU compilers gcc and g++See the print edition