multiple .a files linking issues
John (Eljay) Love-Jensen
eljay@adobe.com
Fri Dec 11 15:19:00 GMT 2009
Hi Robin,
Expanding on Harald's response, the order on the command line for gcc and g++ is important.
g++ /mylib/libA.a /mylib/libB.a myapp.o -o myapp
This is what the linker does in processing from left-to-right:
1. libA.a -- don't need any symbols from there, ignore it.
2. libB.a -- don't need any symbols form there, ignore it.
3. myapp.o -- .o files are linked in wholesale, with outstanding symbols for A and B
4. Hmmm, myapp is missing A and B symbols. ERROR.
Try putting the object files first, and the libraries in dependency order instead:
g++ -o myapp myapp.o /mylib/libB.a /mylib/libA.a
Since B depends on A (but not vice versa, fortunately), B should appear first.
Although not the situation you are running into, sometimes there is a circular dependency between two libraries. One way to resolve that is to specify one library twice:
g++ -o foo main.o /mylib/libAlpha.a /mylib/libBeta.a /mylib/libAlpha.a
A better solution is to combine both libraries into one library. But that's not always feasible.
HTH,
--Eljay
More information about the Gcc-help
mailing list