Reputation: 109
I am new to C++ and trying to understand everything. I know the Linker links the object file to any external files. Correct? Does the linker link the preprocessors? or just additional files?
For instance in a simple Hello World program. Would the linker link with my Hello World Program?
Upvotes: 3
Views: 300
Reputation: 7779
In a very general nutshell, the primarily function of the linker is to package your Hello World program together with any library routines you have called in your program, such as prinf, into an executable file that is ready for the OS to load into memeory and receive transfer of control. This packaging creates the arrangement of code in the program's address space. As part of this task, it this necessary for linker to "resolve" symbols in your code by, for example, assigning to the symbol an address offset within the executable image. The linker also creates a relocation table that contains pointers to certain global symbols that should be absolute memory addresses. Since absolute memory addresses cannot be known at link-time, they are determined at load-time by the OS loader, and the executable images is then patched with the correct absolute addresses before transfer of control.
Upvotes: 1
Reputation: 4525
Linker would link the library and .o files. The compiler will generate the .o files. preprocessor would be handled in compilation process.
For example
step 1: compile: g++ -c relatedFile.cpp
step 2: Link: g++ -o proName relatObjFile.o (external library)
Upvotes: 0