Link problems

Hi guys,

I have a rather strange linking problem. I'm working on a project in C++ on Linux. The project is rather large, and its modules are broken into multiple subdirectories.

I've just written a new executable module called "bigbang", which links to a number of static libraries which are also part of the project. Three of the libraries are:

libconceptgraph.a
libconceptmatch.a
libcompactucgparser.a

The source code of all three libraries reside in their own sub directories.

libconceptgraph.a only links to some system libraries. libconceptmatch.a links to some system libraries and libconceptgraph.a, and libcompactucgparser.a links to some system libraries and libconceptgraph.a and libconceptmatch.a.

I can compile the 3 static libraries without any problem.

However, when I link them together to compile the object file for the executable bigbang, I get linking errors saying that some of the functions used in libcompactucgparser.a are not defined.

I checked the compilation flags and all three libraries are linked to the object file of bigbang.

So, I really have no idea what's happening here. Would anyone be able to help?

Any suggestion would be greatly appreciated.

Thanks a lot.

-D
The order in which you pass the libraries to the linker is important because the GNU linker is stupid.

I never remember which way it goes, but you need either to pass the libraries in this order:
graph, match, parser

or in this order:
parser, match, graph

thanks smith! I will give it a go.

-D
And if you have circular dependencies, it is OK to link against the same library twice to resolve all symbols. It does not affect execution or size of the program.

So worst case scenario, just do

-lgraph -lmatch -lparser -lmatch -lparser

and that _will_ work, though I recommend only doing it if you indeed have circular dependencies (it sounds like you don't).

Topic archived. No new replies allowed.