Author Topic: linking order [SOLVED]  (Read 7689 times)

Offline Leviathan

  • Single posting newcomer
  • *
  • Posts: 7
linking order [SOLVED]
« 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
« Last Edit: June 04, 2006, 12:08:56 pm by Leviathan »

Offline TDragon

  • Lives here!
  • ****
  • Posts: 936
    • Twilight Dragon Media
Re: linking order
« Reply #1 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.
http://tdm-gcc.tdragon.net/ - TDM-GCC compiler suite for Windows (GCC 5.1.0 2015-06-28, 32/64-bit, no extra DLLs)

Offline Balazs

  • Multiple posting newcomer
  • *
  • Posts: 39
Re: linking order
« Reply #2 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.


Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: linking order
« Reply #3 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

Offline Leviathan

  • Single posting newcomer
  • *
  • Posts: 7
Re: linking order
« Reply #4 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.

Offline TDragon

  • Lives here!
  • ****
  • Posts: 936
    • Twilight Dragon Media
Re: linking order
« Reply #5 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.
http://tdm-gcc.tdragon.net/ - TDM-GCC compiler suite for Windows (GCC 5.1.0 2015-06-28, 32/64-bit, no extra DLLs)

Offline Leviathan

  • Single posting newcomer
  • *
  • Posts: 7
Re: linking order [SOLVED]
« Reply #6 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.