News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

linking order [SOLVED]

Started by Leviathan, May 31, 2006, 01:56:30 PM

Previous topic - Next topic

Leviathan

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

TDragon

Quote from: Leviathan on May 31, 2006, 01:56:30 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.
[url="https://jmeubank.github.io/tdm-gcc/"]https://jmeubank.github.io/tdm-gcc/[/url] - TDM-GCC compiler suite for Windows (GCC 9.2.0 2020-03-08, 32/64-bit, no extra DLLs)

Balazs

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.


Michael

Quote from: 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

Hello,

Which C::B revision are you using?

Best wishes,
Michael
[url="http://img207.imageshack.us/img207/9728/411948picture4em.png"]http://img207.imageshack.us/img207/9728/411948picture4em.png[/url]

Leviathan

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.

TDragon

Quote from: Leviathan on June 04, 2006, 12:07:52 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.
[url="https://jmeubank.github.io/tdm-gcc/"]https://jmeubank.github.io/tdm-gcc/[/url] - TDM-GCC compiler suite for Windows (GCC 9.2.0 2020-03-08, 32/64-bit, no extra DLLs)

Leviathan

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.