Thread: Linking files?
View Single Post
Old 02-26-2003, 04:43 PM   #2 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
i don't think that linking is your problem, perhaps you can show us your program and we'll figure out what's wrong.

anyway, here is an explanation of linking:

(compile-time) linking takes the compiled binary generated from your code, and connects all the pieces together into one binary executable file.
for example, let's say you have 2 files, main.cpp and foo.cpp.
foo.cpp contains the foo() function, and main.cpp contains the main() function, and within main() is a call to foo(). when your compiler compiles main.cpp it generates an object file called main.o (visual studio names them main.obj). in this object file is a symbol, which basically tells the linker "the address of function foo goes here".
when all the object files have been created, it's the job of the linker to take them all and create one executable file. the linker looks at main.o, sees the symbol for foo, and looks through all the object files until it finds where foo() is and puts that in its place. that way your main function can correctly call the foo function.
i imagine your ide is invoking the linker (though gcc) automatically when you perform some sort of 'build' command.

linking also comes into play when you use libraries. luckily for you, your compiler knows how to link in standard libraries (ex: iostream), without any help from you.

this explanation leaves out dynamic linking, but you probably don't need to worry about it for now.
joe_bruin is offline   Reply With Quote