0

我想将新的 c++ cpd 库(https://github.com/gadomski/cpd)添加到 ROS 中的一个项目中。我已经在我的 Ubuntu 操作系统中成功安装了 cpd 库。

现在我想在ROS环境下使用它。

在 CMakeList.txt 文件中,我已经添加了

find_package(CPD REQUIRED)

include_directories(include
  ${catkin_INCLUDE_DIRS}
  ${OpenCV_INCLUDE_DIR}
  ${PCL_INCLUDE_DIRS}
  ${CPD_INCLUDE_DIRS}
)

target_link_libraries(background_removal
  ${catkin_LIBRARIES}
  ${OpenCV_LIBRARIES}
  ${PCL_LIBRARIES}
  ${CPD_LIBRARIES}
)

然后在我刚刚添加的源代码中

#include <cpd/nonrigid_lowrank.hpp>

以及示例代码

cpd::NonrigidLowrank reg;
cpd::Registration::ResultPtr result = reg.run(X, Y);

但是在我编译它之后,它会抛出错误: undefined reference to `cpd::NonrigidLowrank::NonrigidLowrank()'

错误:未定义对 `cpd::Registration::run(arma::Mat const&, arma::Mat const&) const' 的引用

我想cpd的库没有链接到ROS,我调用cpd库是不是做错了什么?

4

1 回答 1

3

undefined reference is a linker error, not a compiler error. Your use of include_directories() is OK, but you forgot to also add ${CPD_LIBRARIES} (1)(2) to the target_link_libraries() of your target(s).


(1): Just guessing that FindCPD.cmake "works" the same way as all the other FindXyz.cmake modules. Never worked with CPD myself.

(2): Guessing from your snippet, you will also need to add ${OpenCV_LIBRARIES} and ${PCL_LIBRARIES}...

于 2015-06-17T09:49:14.087 回答