catkin_add_gtest linking error
Around this line in CMakeLists.txt
,
if (CATKIN_ENABLE_TESTING)
catkin_add_gtest(test_mongo_roscpp test/test_mongo_ros.cpp)
target_link_libraries(test_mongo_roscpp warehouse_ros)
add_rostest(test/mongo_ros.test)
endif()
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).
if (CATKIN_ENABLE_TESTING)
catkin_add_gtest(test_mongo_roscpp test/test_mongo_ros.cpp)
endif()
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.