Penguin
Note: You are viewing an old revision of this page. View the current version.

How compiling works under Linux (and Unixies in general)

Note this is the long winded approach, gcc(1) is smart enough to do most of these steps for you automagically. :)

When compiling a C program the first step is to PreProcess? the source. This is done with cpp(1). This will take a .c and some .h files and generate you a .i file( PreProcess?ed) that has all the #include's expanded out, and all the #defines replaced.

gcc(1) then takes a .i file and generates a .s file (assembler information).

as(1) then takes a .s file and generates a .o file (object file).

ld(1) then takes the .o file and links it with any libraries as required and generates an executable or a library.

strip(1) can then optionally remove any unneeded information in the executable (such as debugging information) reducing it's size.

alternatively

gcc foo.c baz.c -o baz

will sort the entire thing out for you :)


SeeAlso? MakefileHowto