简体   繁体   English

Cpp:将库链接到库?

[英]Cpp: Link library to a library?

I am using ROS and I have an external library consisting of a static library foo.a and a path with header.我正在使用 ROS 并且我有一个外部库,它由一个静态库foo.a和一个带有标题的路径组成。 Now my CmakeLists.txt looks like this:现在我的 CmakeLists.txt 看起来像这样:

...
include_directories(/home/foo/include/)
find_library(LIB_TO_Include foo /home/foo/lib/static) //here is the foo.a

cs_add_library(${PROJECT_NAME} src/bar.cc)
catkin_add_gtest(test_bar test/test_bar.cc
             WORKING_DIRECTORY ${CMAKE_BINARY_DIR}})
target_link_libraries(test_bar ${LIBRARY_NAME} ${LIB_TO_Include})
...

So the tests work.所以测试工作。 But when I include this package into another package I get the following errors:但是当我将此包包含到另一个包中时,出现以下错误:

bar.o undefined referenes to functions of foo

So my package does not have any executable to which I could link my external library so how would I integrate it than?所以我的包没有任何可以链接我的外部库的可执行文件,那么我将如何集成它呢? How can I correctly link that external library?如何正确链接该外部库?

One of the object modules (files) in your library has an external reference and uses a function or object from another library.库中的一个对象模块(文件)具有外部引用并使用另一个库中的函数或对象。 When building an application with your library, you need to specify an additional external library that is referenced.使用您的库构建应用程序时,您需要指定一个额外的被引用的外部库。 There may be more than one such external third-party library.这样的外部第三方库可能不止一个。

You can find out how to add external libraries to a сmake project here CMake link to external library您可以在此处找到如何将外部库添加到 сmake 项目的CMake 链接到外部库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM