c++: Undefined reference to ERROR

1k views Asked by At

I want to add new c++ library of cpd (https://github.com/gadomski/cpd) to one project in ROS. I have already successfully installed the cpd library in my Ubuntu OS.

Now I want to use it under ROS environment.

In the CMakeList.txt file, I already added the line of

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

error: undefined reference to `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?

1

There are 1 answers

5
DevSolar On BEST ANSWER

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}...