0

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?

ZYJ
  • 57
  • 6

1 Answers1

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

DevSolar
  • 67,862
  • 21
  • 134
  • 209
  • hey, thx for your reply. I did add the target_link_libraries in my CMakeList file target_link_libraries(background_removal ${catkin_LIBRARIES} ${OpenCV_LIBRARIES} ${PCL_LIBRARIES} ${CPD_LIBRARIES} ) But it didn't work, Without use of CPD, I can successfully run it with OpenCV, PCL. – ZYJ Jun 17 '15 at 11:37
  • Well, the usual stuff: `message( "CPD_LIBARIES: ${CPD_LIBRARIES}" )`, `grep` for the reported-missing symbols in those libraries... not enough information here to give more precise advice. – DevSolar Jun 17 '15 at 11:50
  • you are right, there is no value in the symbol, it's empty. so it does not actually find the cpd libary... – ZYJ Jun 17 '15 at 12:07
  • i manually set target_link_libraries(background_removal /usr/local/lib/libcpd.so) to the pcd lib, it works, but still don't get why it does not work with find_package, but your reply helped a lot – ZYJ Jun 17 '15 at 12:23
  • @ZYJ: There's half a dozen possible reasons. Headers installed but not the libs? Looking for debug libs but only finding release (or vice versa)? Looking for static libs but only having dynamic ones (or vice versa)? Working on Cygwin (where libs get prefxied cyg...) and find module not being prepared for it? Headers in a standard location but libs not (would require `CMAKE_PREFIX_PATH` being set appropriately)? You can debug all this by scattering some `message(...)` entries throughout the find module and checking where it goes wrong. – DevSolar Jun 17 '15 at 12:27