简体   繁体   English

C ++:对ERROR的未定义引用

[英]c++: Undefined reference to ERROR

I want to add new c++ library of cpd ( https://github.com/gadomski/cpd ) to one project in ROS. 我想将cpd的新c ++库( https://github.com/gadomski/cpd )添加到ROS中的一个项目。 I have already successfully installed the cpd library in my Ubuntu OS. 我已经在Ubuntu OS中成功安装了cpd库。

Now I want to use it under ROS environment. 现在我想在ROS环境下使用它。

In the CMakeList.txt file, I already added the line of 在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}
)

then in the source code I just added 然后在我刚刚添加的源代码中

#include <cpd/nonrigid_lowrank.hpp>

as well as the example code 以及示例代码

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

But after I compile it, it throws the error: undefined reference to `cpd::NonrigidLowrank::NonrigidLowrank()' 但是在编译之后,它会引发错误:对`cpd :: NonrigidLowrank :: NonrigidLowrank()的未定义引用

error: undefined reference to `cpd::Registration::run(arma::Mat const&, arma::Mat const&) const' 错误:未定义引用`cpd :: Registration :: run(arma :: Mat const&,arma :: Mat const&)const'

I suppose the library of cpd is not linked to the ROS, Did I do something wrong to call the cpd library? 我想cpd库没有链接到ROS,调用cpd库是否做错了?

undefined reference is a linker error, not a compiler error. undefined reference是链接器错误,而不是编译器错误。 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). 您可以使用include_directories() ,但是您忘记将${CPD_LIBRARIES} (1)(2)也添加到目标的target_link_libraries()中。


(1): Just guessing that FindCPD.cmake "works" the same way as all the other FindXyz.cmake modules. (1):只是猜测FindCPD.cmake与所有其他FindXyz.cmake模块的工作方式相同。 Never worked with CPD myself. 我自己从未与CPD合作过。

(2): Guessing from your snippet, you will also need to add ${OpenCV_LIBRARIES} and ${PCL_LIBRARIES} ... (2):从${OpenCV_LIBRARIES}猜测,您还需要添加${OpenCV_LIBRARIES}${PCL_LIBRARIES} ...

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

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