tags:

views:

156

answers:

2

Hello everyone,

I've not visited this site with a question, so I'm a bit clumsy with the interface, but here goes...

When I examine the code generated by gcc -v -o proggy.exe proggy.o I find that the command line expands into a large bunch of library options and libraries, all of which are linked using collect2.exe. What happened to ld.exe? Why don't I see that? Can someone explain to me what collect2.exe does?

Thanks, Mark Allyn

+2  A: 

collect2 is a utility used to generate a table of constructors that __main (an auto-generated function called at the beginning of main) depends on. Normally you don't see it because it's named ld on the file system, and it in turn calls the real ld (typically called real-ld, although collect2 will check a number of places looking for it)

Michael Mrozek
Mr. Mrozek, Thanks for your reply. Next question: If I use LD.EXE on the command line, what happens to the code? Suppose I have ld.exe -L/some_lib proggy.o -lsome_lib_lib. How does this get expanded?Your previous answer to my initial question was very enlightening!Thanks,Mark
allynm
Worth noting that modern ELF systems won't need that collection (which of course is a nasty hack). They use the ctors and dtors sections of ELF for con- and destructors.
Johannes Schaub - litb
A: 

GCC uses a utility called collect2 on nearly all systems to arrange to call various initialization functions at start time. [link]

Kirill V. Lyadvinsky