catkin_make fails when linking on reference to ros::NodeHandle
EDIT I've worked out how to set the CMAKE flags and thus have been able to capture the link statement that fails. Its shown it at the bottom of this post.
I am doing an assignment at Uni whereby I need to build a package that incorporates code that was developed outside of ROS. I'm adding ROS functionality to it. I'm not bringing the source files into my project folder, but rather, including their normal locations in my CMakeLists.txt. (Don't want two versions floating around.)
I've now been able to make the original program run as a ROS Node using rosrun mypackage mypackage_node
.
The problem I'm having is that as soon as I include a statement in my code that uses ROS functionality, the catkin_make build fails during linking with the following error:
CMakeFiles/gwbrb_node.dir/src/gwbrb.cpp.o: In function `GUMonitor::callback(guWb::wb_types, gsw_simple_message*)':
/home/user/src/MPL/Gao/posix/guWbR/src/gwbrb/src/gwbrb.cpp:123: undefined reference to `ros::NodeHandle::NodeHandle(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > > const&)'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I have included "ros/ros.h", and the statement that causes the error is ros::NodeHandle nForWNb;
With this statement commented out, it works as stated above.
Because I suspected the ROS libraries were not being located, I decided to print the value of ${catkin_LIBRARIES} in my CMakeList.txt file, and have found that it evaluates to NULL. This is not right, since I am executing That is the wrong place to print its value... source ~/ros_catkin_ws/install_isolated/setup.bash
when I open my shell.
Now, when I print the value of ${catkin_LIBRARIES}, just before the target_link_libraries()
clause, it holds the value:
/home/user/ros_catkin_ws/install_isolated/lib/libroscpp.so;/usr/lib/x86_64-linux-gnu/libboost_signals.so;/usr/lib/x86_64-linux-gnu/libboost_filesystem.so;/home/user/ros_catkin_ws/install_isolated/lib/librosconsole.so;/home/user/ros_catkin_ws/install_isolated/lib/librosconsole_log4cxx.so;/home/user/ros_catkin_ws/install_isolated/lib/librosconsole_backend_interface.so;/usr/lib/liblog4cxx.so;/usr/lib/x86_64-linux-gnu/libboost_regex.so;/home/user/ros_catkin_ws/install_isolated/lib/libxmlrpcpp.so;/home/user/ros_catkin_ws/install_isolated/lib/libroscpp_serialization.so;/home/user/ros_catkin_ws/install_isolated/lib/librostime.so;/usr/lib/x86_64-linux-gnu/libboost_date_time.so;/usr/lib/x86_64-linux-gnu/libboost_system.so;/usr/lib/x86_64-linux-gnu/libboost_thread.so;/usr/lib/x86_64-linux-gnu/libpthread.so;/home/user/ros_catkin_ws/install_isolated/lib/libcpp_common.so;/home/user/ros_catkin_ws/install_isolated/lib/libconsole_bridge.so
I think something in my CMakeLists.txt file is causing this problem, but I don't know where, or how to discover ...
Since I've worked out how to use the '-v invocation', I am able to see the command given for each compile and link step. Using this info, I'm going to compare a working catkin package build with the build steps of the original project, and this build. Between the three, I hope I can figure it out.