Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: Leviathan on May 31, 2006, 01:56:30 pm

Title: linking order [SOLVED]
Post by: Leviathan on May 31, 2006, 01:56:30 pm
Hi, and sorry if this was asked before. I did a search but didn't find anything.
In my current project, I get a lot of undefined references when compiling with gnu gcc. With Visual C++ 2005 it works, and the functions are definitively there, so I assume the order in which codeblocks passes the object-files to the linker is wrong, but neither can I see the command-line that codeblocks is executing, nor have I found a way to change the order.

Any ideas? Thanks in advance
Title: Re: linking order
Post by: TDragon on May 31, 2006, 03:48:33 pm
...neither can I see the command-line that codeblocks is executing, ...
Settings -> Compiler and debugger -> Other -> Compiler logging -> Full command line.

Invaluable for troubleshooting these issues.
Title: Re: linking order
Post by: Balazs on June 02, 2006, 08:15:52 pm
Object files order doesn't matter, the only thing that does matter is the order of libs.
At the end of the list should be that lib, that doesn't use any symbols from the others.
For example: -l1 -l2 -l3
if
-l1 uses symbols from -l2 or -l3 (or both)
-l2 uses symbols from -l3
-l3 doesn't use symbols from the others

--
Greets,
B.

Title: Re: linking order
Post by: Michael on June 03, 2006, 11:09:36 pm
Hi, and sorry if this was asked before. I did a search but didn't find anything.
In my current project, I get a lot of undefined references when compiling with gnu gcc. With Visual C++ 2005 it works, and the functions are definitively there, so I assume the order in which codeblocks passes the object-files to the linker is wrong, but neither can I see the command-line that codeblocks is executing, nor have I found a way to change the order.

Any ideas? Thanks in advance

Hello,

Which C::B revision are you using?

Best wishes,
Michael
Title: Re: linking order
Post by: Leviathan on June 04, 2006, 12:07:52 pm
Hi,

thanks for your answers. I found the problem: One of the files (the one with the undefined references) was being compiled with g++, the rest with gcc so I guess the problem had to do with name-mangling or something.
Anyway, the full command line-logging showed me my mistake.

Btw.: I noticed that for the linking-step, g++ is used. Is this hard-coded or is this again a misconfiguration on my part? Doesn't seem to cause problems, just wondering.
Title: Re: linking order
Post by: TDragon on June 04, 2006, 04:48:06 pm
Btw.: I noticed that for the linking-step, g++ is used. Is this hard-coded or is this again a misconfiguration on my part?
Neither. It is the default, being the easiest way to do things, but you could change it (no reason to) in the advanced compiler configuration.

Pedantic:
For linking, any of four possible executables (gcc, g++, mingw32-gcc, mingw32-g++) just act as frontends for ld anyway -- just as, in compiling, they act as frontends for cc1 or cc1plus. You can compile C programs with g++ and C++ programs with gcc, as long as you pass the right options.
Title: Re: linking order [SOLVED]
Post by: Leviathan on June 04, 2006, 06:21:40 pm
Thanks for the explanation. I know that g++ and gcc act as frontends but as far as I understand it, the pass some parameters to the backend depending on the language you're compiling for, so I thought g++ as a frontend to ld might still do something different than gcc.