ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

problem with linking gtests in catkin

asked 2013-09-24 07:40:32 -0500

brice rebsamen gravatar image

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 ...
(more)
edit retag flag offensive close merge delete

Comments

1

First, you want to keep the check for CATKIN_ENABLE_TESTING around all your testing stuff (not that it makes a difference but the case that it can be omitted might not be supported in the future).

Dirk Thomas gravatar image Dirk Thomas  ( 2013-09-24 07:50:04 -0500 )edit
1

Have you tried to add the target link libraries to you library target?

Dirk Thomas gravatar image Dirk Thomas  ( 2013-09-24 07:54:29 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2013-09-24 11:40:45 -0500

brice rebsamen gravatar image

As pointed by Dirk Thomas, the solution was to target link my libraries with the required libraries, and do that in all packages depended upon.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2013-09-24 07:40:32 -0500

Seen: 1,737 times

Last updated: Sep 24 '13