Does the linking process start from the object file containing main? |
You can link files that don't contain main.
Order of linking is up to whoever wrote the linker.
Static linking using GCC:
The linker examines object files and library files in the order they're given on the command line, from left to right.
When it encounters an object file, it makes a note of everything exported and everything needed.
When it encounters a library file, it examines each object inside that library in turn and *only* if that object has something that is on the needed list does it add all that objects exports to the list of everything exported. If that object doesn't have anything on the needed list, it is skipped. However, if any one object file in that library does get used, then the linker cycles back over all the object files again; so object files can get multiple chances to get their symbols exported.
There are some finer details here, but basically it's possible for objects inside libraries to get ignored if, at the point the linker is looking at them, it doesn't need them. If something *later* does need it, the linker (by default) doesn't go back. This is why linking order in static linking makes a difference.
Other linker and dynamic linking, I couldn't tell you; I only know exactly how static linking on GCC works because of experience paying close attention to the link order sometimes.