views:

130

answers:

3

I'm working in a Linux environment with C++, using the GCC compiler.

I'm currently working on modifying and upgrading a large pre-existing body of code. As part of this, it has been necessary to add quite a large number of small references throughout the code in a variety of places to link things together, and also to add in several new external code libraries. There is also quite a large and complex structure of Makefiles linked to a configure.ac file to handle the build process.

Upon starting the build process everything compiles without a problem, but comes back with the dreaded linker error when trying to use a newly added custom code library we've created. We have now been through a vast amount of code with a fine tooth comb looking for spelling mismatches, checking the order that all the libraries are included in the build process, and checked that the .o files created contain what we need using dumps, and all are as and where they should be. We've also tested the library separately and the problem definitely doesn't lie there.

In short, we've tried most things that you should normally do in these scenarios.

Is there a tool for C++ that can detect linker errors automatically, in a similar vein to cppcheck or splint (both of which we have run to no avail) that could help here?

+3  A: 

Don't know your platform, but I spent sometime with linker problems in gcc till I realized that the static library (.a) linking requires specific ordering, its not the same to link gcc object.o first.a second.a than gcc object.o second.a first.a.

Arkaitz Jimenez
We've been looking at this as a possible cause, and so far it doesn't seem to have made a difference. The main problem as I said is that its a large pre-existing code body, and the lead programmer on it is no longer with us. As a result, we're still working out exactly how the Configure file works.We'll take a close look at the ordering though, cheers for the help!
Smallgods
After looking into it further, turns out there was one combination of ordering we hadn't tried, which magically (after the lovely 1-2 hour long build process) decided to work this time. Thanks for the advice.
Smallgods
+2  A: 

HI

FWIW (not much) I try to tackle this sort of issue by using another linker as I have access to a couple of different platforms. If you can use another linker you will find either:

a) the program links, which transforms your problem from 'why doesn't it link ?' to 'what are the differences between linkers and linking ?' which isn't exactly a step forward, but sometimes a step to one side gives you a different perspective from which you can see a solution;

OR

b) it fails to link, in which case the other linker might give more useful information about why it fails.

Not much help I know, I'd downvote the answer if I could.

Regards

Mark

High Performance Mark
I like the idea of comparing two linker outputs, thats not an approach we've tried yet. Will give it a shot, cheers! Its mainly more detailed feedback on the error we're after - the current error isn't really that helpful at all..
Smallgods
A: 

What is the error that is causing you so much trouble?

DrPizza
This should be a comment on the question
Michael Donohue
waaaaaaaaaaaaaaaaaaaaaaah.
DrPizza