我的项目有3个代码“块”:2个静态库:LibraryA和LibraryB,以及控制台应用程序:Client。

客户端调用LibraryA,而LibraryA调用LibraryB。客户端根本不使用LibraryB。

现在,我已经对Library A进行了很好的编译,但是当我尝试编译客户端时,由于无法找到LibraryB而收到一个错误。这是构建日志所说的导致错误的内容:

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()'

我不确定问题是什么,我们将不胜感激。
我在带有GNU GCC编译器的Ubuntu 14.04(VirtualBox)中使用Code::Blocks 13.12

提前致谢。
让我知道是否需要更多信息。

更新

我修改了设置,从一开始就删除了-L命令,所以现在看起来像这样(带有实际的库名):
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()'

库A =计划轨迹,库B = CMetInterpIf

如果有帮助的话,后两个错误也始终存在。顺便说一句,我正在使用相对路径,因为最终我需要将此路径移植到另一台机器上。我可以更改为绝对路径,如果有帮助的话
nm -C libCMetInterpIf.a | fgrep 'agsfirecontrol::CMetInterpIf::CMetInterpIf()'
nm: CEnvironment.o: no symbols
nm: CMetInterpIf.o: no symbols
nm: CMathUtilities.o: no symbols

最佳答案

为了成功链接,您需要为链接器提供程序所需的所有库,包括那些与其他库相关的库。您的客户端程序可能不会直接调用LibraryB中的内容,但是它仍然是一个依赖项,因为LibraryA需要它。尝试这个:

g++ -o bin/Debug/Client obj/Debug/main.o /path/to/LibraryA.a /path/to/LibraryB.a

真的不需要-L/path/to/libraryA ... LibraryA.a的冗长性-您可以像上面一样做,直接命名文件,或者假设您的库是使用更标准的libA.a模式命名的,则可以使用-L/path/to/libraryA ... -lA--l<something>标志搜索一个名为的库lib<something>.alib<something>.so

08-17 00:55