A compiler translates a program from one language into another, here from C into the assembly language of the processor; the translation is called compilation. The assembler then encodes the assembly as machine code in an object file: machine code with holes, together with a table of the names it defines and the names it uses. Each name in that table is a symbol. The linker combines object files and libraries into one executable file, a file the operating system can load and start; this step is linking, and a used symbol that no input defines is an undefined reference.
gcc runs them in turn, and the options -E, -S and -c stop it after the first, second or third. The linker fills the holes left in the object file with the addresses of the library’s code.أمثلة
Example 1.3 (Two link errors)
In the session, gcc main.o -o broken forgets square.o: main.o uses square and square_calls and nobody defines them, so the linker reports two undefined references (and two warnings that follow from the same missing data symbol). The last command links twice.o, which defines a second square: now the symbol is defined twice and the linker cannot choose. Note that the compiler accepted every file: each error belongs to the link, where the files meet.