Ask Your Question

catkin_add_gtest linking error

asked 2016-04-20 12:18:11 -0500

130s gravatar image

updated 2016-04-20 12:37:02 -0500

Around this line in CMakeLists.txt,

  catkin_add_gtest(test_mongo_roscpp test/test_mongo_ros.cpp)
  target_link_libraries(test_mongo_roscpp warehouse_ros)

Running test results in to undefined reference error as follows.

$ catkin_make run_tests
#### Running command: "make run_tests -j8 -l8" in "/home/roslinguini/cws_planning/build"
[ 33%] Built target gtest
[ 66%] Built target gtest_main
Linking CXX executable /home/roslinguini/cws_planning/devel/lib/warehouse_ros/test_mongo_roscpp
CMakeFiles/test_mongo_roscpp.dir/test/test_mongo_ros.cpp.o: In function `MongoRos_MongoRos_Test::TestBody()':
test_mongo_ros.cpp:(.text+0x2c7): undefined reference to `mongo_ros::dropDatabase(std::string const&, std::string const&, unsigned int, float)'
test_mongo_ros.cpp:(.text+0xf42): undefined reference to `mongo::LT'
test_mongo_ros.cpp:(.text+0xf60): undefined reference to `mongo::GT'
test_mongo_ros.cpp:(.text+0x1839): undefined reference to `mongo::LT'
test_mongo_ros.cpp:(.text+0x22f7): undefined reference to `ros::console::g_initialized'
test_mongo_ros.cpp:(.text+0x2307): undefined reference to `ros::console::initialize()'
collect2: error: ld returned 1 exit status
make[3]: *** [/home/roslinguini/cws_planning/devel/lib/warehouse_ros/test_mongo_roscpp] Error 1
make[2]: *** [warehouse_ros/CMakeFiles/test_mongo_roscpp.dir/all] Error 2
make[1]: *** [CMakeFiles/run_tests.dir/rule] Error 2
make: *** [run_tests] Error 2
Invoking "make run_tests -j8 -l8" failed

Removing target_link_libraries (like following) doesn't seem to change the result. So I assume the error occurs at catkin_add_gtest (I have no idea whether linking should occur here though).

  catkin_add_gtest(test_mongo_roscpp test/test_mongo_ros.cpp)

How can I fix this?

I've been also trying with catkin_tools (the most recently with version 0.4.1) on Travis CI but looks like the result is similar/the same. You can take a look at a result where the error starts around here. And full code is in this PR.

Thank you.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2016-04-20 15:34:14 -0500

Dirk Thomas gravatar image

Your target test_mongo_roscpp is only linking against warehouse_ros but nothing else. At least roscpp is missing as well as something providing the symbols related to mongo.

If you have find_package()-ed all dependencies it might be suffcient to link against ${catkin_LIBRARIES}.

I commented on another CMake problem in your PR:

edit flag offensive delete link more


Your comment in PR helps me to move forward, thanks!

Your target test_mongo_roscpp is only linking against warehouse_ros but nothing else.

I thought with target_link_libraries I can trasitively link targets, no? ref

130s gravatar image 130s  ( 2016-04-20 16:43:11 -0500 )edit

No, not across CMake projects.

Dirk Thomas gravatar image Dirk Thomas  ( 2016-04-20 17:00:41 -0500 )edit

answered 2016-04-20 15:12:08 -0500

joq gravatar image

You probably need to add <test_depend>rosunit</test_depend> to your package.xml.


edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-04-20 12:18:11 -0500

Seen: 1,272 times

Last updated: Apr 20 '16