如何将两个静态库链接到一个Code::Blocks项目
How to link 2 static libraries to one Code::Blocks project
我的项目有3个代码"块":2个静态库:LibraryA和LibraryB,以及一个控制台应用程序:Client。
客户端调用LibraryA,LibraryA调用LibraryB。客户端根本不使用LibraryB。
现在,我已经很好地编译了库A,但当我试图编译客户端时,我遇到了一个错误,因为它找不到库B。以下是构建日志中导致错误的内容:
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()'
我不知道问题出在哪里,我们非常感谢您的帮助。我在Ubuntu 14.04(VirtualBox)中使用代码::Blocks 13.12和GNU GCC编译器
提前谢谢。如果需要更多信息,请告诉我。
更新
一开始我修改了设置,去掉了-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()'
LibraryA=PlanTrajectory,LibraryB=CMetInterpIf
如果有帮助的话,第二个2个错误也一直存在。顺便说一句,我使用相对路径,因为最终我需要它可以移植到另一台机器上。我可以改变到绝对路径,如果这将有助于任何
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>.a
或lib<something>.so
的库。
相关文章:
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- 删除一个线程上有数百万个字符串的大型哈希映射会影响另一个线程的性能
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 运行同一解决方案的另一个项目的项目
- 挂起和取消挂起一个文件DLL
- 用C++中的一个变量定义一个常量
- 函数向量_指针有不同的原型,我可以构建一个吗
- 在c++中用vector填充一个简单的动态数组
- 如何在选项卡视图Qt中设置一个新项目,并保存以前的项目
- 预处理器:插入结构名称中的前一个行号
- 我在c++代码中生成了一个运行时#3异常
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- 从链接列表c++中删除一个项目
- 告诉一个 const char 数组,除了编译时 C 样式的字符串外,它不以 '