let's analyse "collect2: ld returned 1 exit status"?

22,160

As H2CO3 alludes to, and to get an idea of how hard it would be to manually link, try running g++ with the verbose switch (-v). It will output the commands (along with some other information) for all the steps in the process (pre-process, compile, assemble, link).

For instance, building a simple 'Hello, World' with g++ on Cygwin, yields:

/usr/lib/gcc/i686-pc-cygwin/3.4.4/collect2.exe -Bdynamic --dll-search-prefix=cyg
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../crt0.o -L . -L/usr/lib/gcc/i686-pc-cygwin/3.4.4
-L/usr/lib/gcc/i686-pc-cygwin/3.4.4 -L/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../..
/tmp/cc4btl0k.o -lfoo -lstdc++ -lgcc -lcygwin -luser32 -lkernel32 -ladvapi32 -lshell32 -lgcc

...for the linking phase.

Share:
22,160
lImbus
Author by

lImbus

simple Software-Developer for some years now with serious intrests in hardware.writing open source software, working on hardware/electronics too.

Updated on July 09, 2022

Comments

  • lImbus
    lImbus almost 2 years

    I know this indicates a linker problem, mostly unresolved symbols. I know that to resolve that problem / to get rid of that errormessage, one would have to provide much more information. I know there is a lot of questions on resolving this problems on SO already.

    My questions aims at helping to understand make and ld, to find out what (and who) is trying to express what with this line.

    collect2: ld returned 1 exit status
    
    • What does "collect2:" mean? Is it a step make invokes ? I can't find an executable with that name on my system.
    • Does it mean I am using ld ? I configured my project / Makefile so that g++ should do the linking, so why is LD still involved
    • Who is writing that message ? make ? ld ? g++ ?
    • Is there a meaningful list of possible exit codes ?