It doesn't seem like you understand what you asked the compiler driver (gcc) to execute in the first command. Since you did not specify the -c option (only for compilation), you asked gcc to compile the two source files and link them to the standard library (libc) and run at startup (crt0, usually) to make the program work. crt0 tries to enter your program by calling main (), which is an undefined character that the linker cannot find. It cannot find it because you do not have the main () in any of your .c files, right?
So, to your real question: "Why are the symbols of the shared library not allowed during the link?" Answer: what do you mean by "link time"? By default, a dynamically linked program is not βboundβ until it is launched (or perhaps not even then, depending on your system).
On Linux, you can see which dynamic libraries are program dependent with the ldd command ("otool -L" is used on Mac OS). At the output of ldd, you will find out which dynamic libraries the program depends on, which is found in the library search path and which of them cannot be found (if any).
When you run a dynamic program, the dynamic linker that was associated with it detects and loads the dynamic libraries that the program depends on, and "fixes" links to external characters. If any of them fails, your program will not start. One of all previously unresolved characters has been resolved, the dynamic linker is returned, and the C runtime will call your main () function. (This is slightly different from Mac OS, but similar in essence, the connection occurs after starting your program.)
Wexxor
source share