Reputation: 73
I have 3 code "chunks" for my project: 2 static libraries: LibraryA and LibraryB, and a console application: Client.
The client calls LibraryA and LibraryA calls LibraryB. The client does NOT use LibraryB at all.
Right now, I have Library A compiled just fine but when I try to compile the client I get an error because it cannot locate LibraryB. Here is what the Build Log says leading upt to the error:
g++ -L/path/to/LibraryA -L/path/to/LibraryB/ -o bin/Debug/Client obj/Debug/main.o LibraryA.a "LibraryB.a"
LibraryA.a(LibraryA.o): In function `LibraryA_Class::function(args)':
LibraryA.cpp:136: undefined reference to `namespace::LibraryB::LibraryB_class()'
I'm not sure what the issue is, any help is appreciated. I'm using Code::Blocks 13.12 in Ubuntu 14.04 (VirtualBox) with the GNU GCC Compiler
Thanks in advance. Let me know if more information is needed.
Update
I modified the settings to take out the -L commands at the beginning so now it looks like this (with the actual library names):
g++ -o bin/Debug/Client obj/Debug/main.o ../../Wrapper/FCS_PlanTrajectory/bin/Debug/libFCS_PlanTrajectory.a ../../BAE/lib_obj/libCMetInterpIf.a
../../Wrapper/FCS_PlanTrajectory/bin/Debug/libFCS_PlanTrajectory.a(PlanTrajectory.o): In function `PlanTrajectory_Class::planSingleTrajectory(unsigned char, Position_T const&, double, double*, Position_T const&, unsigned char, std::vector<agsfirecontrol::METOCGridPoint_T, std::allocator<agsfirecontrol::METOCGridPoint_T> > const&, unsigned char, double, double, double*, Position_T*, double&, double&, unsigned int&, agsfirecontrol::AgsFireControlCompliance_T&)':
/home/angela/Work/FCS/Code/Wrapper/FCS_PlanTrajectory/src/PlanTrajectory.cpp:136: undefined reference to `agsfirecontrol::CMetInterpIf::CMetInterpIf()'
/home/angela/Work/FCS/Code/Wrapper/FCS_PlanTrajectory/src/PlanTrajectory.cpp:193: undefined reference to `agsfirecontrol::CMetInterpIf::~CMetInterpIf()'
/home/angela/Work/FCS/Code/Wrapper/FCS_PlanTrajectory/src/PlanTrajectory.cpp:193: undefined reference to `agsfirecontrol::CMetInterpIf::~CMetInterpIf()'
LibraryA = PlanTrajectory, LibraryB = CMetInterpIf
The second 2 errors have always been present also if that helps at all. Btw, I'm using relative paths because eventually I need this to be portable to another machine. I can change to absolute paths if it will help anything
nm -C libCMetInterpIf.a | fgrep 'agsfirecontrol::CMetInterpIf::CMetInterpIf()'
nm: CEnvironment.o: no symbols
nm: CMetInterpIf.o: no symbols
nm: CMathUtilities.o: no symbols
Upvotes: 1
Views: 664
Reputation: 62379
In order to successfully link, you need to provide the linker with all the libraries needed by the program, including those that are dependencies of other libraries. Your client program may not directly call things in LibraryB, but it is still a dependency, because LibraryA needs it. Try this:
g++ -o bin/Debug/Client obj/Debug/main.o /path/to/LibraryA.a /path/to/LibraryB.a
There's not really a need for the -L/path/to/libraryA ... LibraryA.a
verbosity - you can either do like above, naming the files directly, or, assuming your libraries are named using the more standard pattern of libA.a
, you can use -L/path/to/libraryA ... -lA
- the -l<something>
flag searches for a library named lib<something>.a
or lib<something>.so
.
Upvotes: 1