Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

problem with linking gtests in catkin

I'm migrating my code to catkin. So far so good, but I've been stuck on that one for some time already.

I'm building a package with some unit tests (gtest), and I get linker errors. The weird thing is that I am using the same linking command as for my executables.

here is my CMakeLists:

cmake_minimum_required(VERSION 2.8.3)
project(bag_of_tricks)

find_package(catkin REQUIRED COMPONENTS roscpp serializable)
find_package(OpenCV REQUIRED)
find_package(Boost REQUIRED COMPONENTS thread)

catkin_package(
  INCLUDE_DIRS include
  LIBRARIES bag_of_tricks
  CATKIN_DEPENDS roscpp serializable
  DEPENDS Boost rt OpenCV
)

include_directories(include ${catkin_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS})

add_library(bag_of_tricks
  src/high_res_timer.cpp
  src/image_region_iterator.cpp
  src/lockable.cpp

  include/bag_of_tricks/high_res_timer.h
  include/bag_of_tricks/image_region_iterator.h
  include/bag_of_tricks/bag_of_tricks.h
  include/bag_of_tricks/lockable.h
)

add_executable(bag_of_tricks_dummy src/bag_of_tricks_dummy.cpp)
target_link_libraries(bag_of_tricks_dummy bag_of_tricks ${catkin_LIBRARIES} ${Boost_LIBRARIES} rt)

catkin_add_gtest(test_bag_of_tricks_hrt src/test_hrt.cpp)
if(TARGET test_bag_of_tricks_hrt)
  target_link_libraries(test_bag_of_tricks_hrt bag_of_tricks ${catkin_LIBRARIES} ${Boost_LIBRARIES} rt)
endif()

catkin_add_gtest(test_bag_of_tricks_lockable src/test_lockable.cpp)
if(TARGET test_bag_of_tricks_lockable)
  target_link_libraries(test_bag_of_tricks_lockable bag_of_tricks ${catkin_LIBRARIES} ${Boost_LIBRARIES} rt)
endif()

And these are the errors I get (with VERBOSE=1):

Linking CXX executable /data/driving_repos/rdr_v2/devel/lib/bag_of_tricks/test_bag_of_tricks_hrt
cd /data/driving_repos/rdr_v2/build/libraries/bag_of_tricks && /usr/bin/cmake -E cmake_link_script CMakeFiles/test_bag_of_tricks_hrt.dir/link.txt --verbose=1
/usr/local/bin/c++   -g    CMakeFiles/test_bag_of_tricks_hrt.dir/src/test_hrt.cpp.o  -o /data/driving_repos/rdr_v2/devel/lib/bag_of_tricks/test_bag_of_tricks_hrt -rdynamic -L/data/driving_repos/rdr_v2/build/gtest ../../gtest/libgtest.so /data/driving_repos/rdr_v2/devel/lib/libbag_of_tricks.so /opt/ros/hydro/lib/libroscpp.so -lpthread -lboost_signals-mt -lboost_filesystem-mt -lboost_system-mt /opt/ros/hydro/lib/libcpp_common.so /opt/ros/hydro/lib/libroscpp_serialization.so /opt/ros/hydro/lib/librostime.so -lboost_date_time-mt -lboost_thread-mt /opt/ros/hydro/lib/librosconsole.so -lboost_regex-mt -llog4cxx /opt/ros/hydro/lib/libxmlrpcpp.so /data/driving_repos/rdr_v2/devel/lib/libserializable.so /data/driving_repos/rdr_v2/devel/lib/libyaml_cpp.so -lboost_thread-mt -lrt -lpthread /opt/ros/hydro/lib/librosconsole.so -lboost_regex-mt -llog4cxx /opt/ros/hydro/lib/libxmlrpcpp.so -lrt -Wl,-rpath,/data/driving_repos/rdr_v2/build/gtest:/data/driving_repos/rdr_v2/devel/lib:/opt/ros/hydro/lib 
/data/driving_repos/rdr_v2/devel/lib/libbag_of_tricks.so: undefined reference to `boost::this_thread::interruption_point()'
/data/driving_repos/rdr_v2/devel/lib/libbag_of_tricks.so: undefined reference to `ros::console::print(ros::console::FilterBase*, log4cxx::Logger*, ros::console::levels::Level, char const*, int, char const*, char const*, ...)'
/data/driving_repos/rdr_v2/devel/lib/libbag_of_tricks.so: undefined reference to `ros::console::initialize()'
/data/driving_repos/rdr_v2/devel/lib/libbag_of_tricks.so: undefined reference to `boost::this_thread::disable_interruption::~disable_interruption()'
/data/driving_repos/rdr_v2/devel/lib/libserializable.so: undefined reference to `boost::filesystem3::path::filename() const'
/data/driving_repos/rdr_v2/devel/lib/libbag_of_tricks.so: undefined reference to `ros::console::initializeLogLocation(ros::console::LogLocation*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, ros::console::levels::Level)'
/data/driving_repos/rdr_v2/devel/lib/libbag_of_tricks.so: undefined reference to `boost::detail::get_current_thread_data()'
/data/driving_repos/rdr_v2/devel/lib/libserializable.so: undefined reference to `boost::system::system_category()'
/data/driving_repos/rdr_v2/devel/lib/libbag_of_tricks.so: undefined reference to `clock_gettime'
/data/driving_repos/rdr_v2/devel/lib/libbag_of_tricks.so: undefined reference to `ros::console::setLogLocationLevel(ros::console::LogLocation*, ros::console::levels::Level)'
/data/driving_repos/rdr_v2/devel/lib/libserializable.so: undefined reference to `boost::filesystem3::detail::rename(boost::filesystem3::path const&, boost::filesystem3::path const&, boost::system::error_code*)'
/data/driving_repos/rdr_v2/devel/lib/libbag_of_tricks.so: undefined reference to `ros::console::g_initialized'
/data/driving_repos/rdr_v2/devel/lib/libserializable.so: undefined reference to `boost::filesystem3::path::wchar_t_codecvt_facet()'
/data/driving_repos/rdr_v2/devel/lib/libserializable.so: undefined reference to `boost::system::generic_category()'
/data/driving_repos/rdr_v2/devel/lib/libbag_of_tricks.so: undefined reference to `ros::console::checkLogLocationEnabled(ros::console::LogLocation*)'
/data/driving_repos/rdr_v2/devel/lib/libbag_of_tricks.so: undefined reference to `boost::this_thread::disable_interruption::disable_interruption()'
/data/driving_repos/rdr_v2/devel/lib/libserializable.so: undefined reference to `boost::filesystem3::path::parent_path() const'
collect2: ld returned 1 exit status

You can see in the linker command that all the libraries seem to be here (-lrt provides clock_gettime for instance, boost_thread and boost_filesystem are here as well, rosconsole is there ...)

Again, this is the same linking command as the bag_of_tricks_dummy executable, which calls some of the functions from my library.

I also tried with if(CATKIN_ENABLE_TESTING) as I have seen in some packages, I have tried to remove the conditional part, I tried with gtest as a test_depend in package.xml, and I'm running out of ideas now.