PDA

View Full Version : programming rant unrelated to DC



Scoofy12
04-15-2005, 12:46 AM
warning: not interesting to non (unix) hackers

so... am i just a complete idiot for not knowing this fact?

<rant>
so I've been working on my toolchain to build fullblown programs for my nic simulator (gcc 3.2 and binutils that build binaries for a subset of the MIPS architecture, with a few extra instructions, plus the newlib C library)... i just spent half a day trying to figure out wtf i could have done to my compiler (i only made small changes) that made the linker fail to link with my C library, when it had no problem doing so before. even after i put the compiler back the way it was, it had problems. did you guys have any idea that library linking arguments to gcc or ld are ORDER DEPENDENT! like the -lc/-lm/-lpthread has to go AFTER your object files! wtf!? since when does order of command line arguments matter? it's not clear in the man page either. if you know this fact ahead of time and go back to read the man page, you could maybe see how part of it could be interpreted to mean that, sort of. but its not at all clear. the only reason i found it out was that i happened to type it the right way one time and it worked, and i eventually figured out that that was the only difference.
stupid. really stupid
</rant>

rsbriggs
04-15-2005, 12:58 AM
Yes, order matters. It's because multiple passes aren't made through the libraries to resolve symbols. If all the symbols aren't defined after making one pass through the libraries you specify, in the order you specify them, the link will fail...

You should see the gyrations I have to go through with an older copy of GCC (2.92) to link in the Oracle 8.x Pro-C libraries. I think that -lm appears about 8 times in different places in the link command line, and taking out any one of them makes the link fail...

Dyyryath
04-15-2005, 10:12 AM
You're not alone, Scoofy. I've always found that somewhat annoying...