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

catkin_make fails when linking on reference to ros::NodeHandle

asked 2014-04-22 20:49:25 -0500

Nap gravatar image

updated 2014-04-23 01:52:50 -0500

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 source ~/ros_catkin_ws/install_isolated/setup.bash when I open my shell. That is the wrong place to print its value...
Now, when I print the value of ${catkin_LIBRARIES}, just before the target_link_libraries() clause, it holds the value:


I think something in my CMakeLists.txt file is causing this problem, but I don't know where, or how to discover ... (more)

edit retag flag offensive close merge delete


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.

Nap gravatar image Nap  ( 2014-04-23 20:36:29 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2014-04-24 00:18:31 -0500

Nap gravatar image

solved the problem, I was setting the wrong stdlib arguement in the CMAKE_CXX_FLAGS variable . `set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++")` needed to become `set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libstdc++")`.

edit flag offensive delete link more

answered 2014-04-22 21:06:58 -0500

BennyRe gravatar image

Uncomment the CATKIN_DEPENDS line in

INCLUDE_DIRS ${MPL_DIR}/Gao/posix/gswb ${MPL_DIR}/Gao/Common
#  LIBRARIES demo_webots_ros_driver
#  CATKIN_DEPENDS roscpp rospy std_msgs
#  DEPENDS system_lib
edit flag offensive delete link more


Benny, done but no change, same problem still persists.

Nap gravatar image Nap  ( 2014-04-22 22:54:16 -0500 )edit

Sorry I went over the CMakeLists.txt documentation again and it seems I got the meaning of catkin_package wrong.

BennyRe gravatar image BennyRe  ( 2014-04-23 02:03:04 -0500 )edit

As I have no experience with clang I can't help you anymore. The only thing that is strange to me is that the roscpp lib is searched in your catkin workspace and not in /opt/ros/ but I also have no experience with this install_isolated thing.

BennyRe gravatar image BennyRe  ( 2014-04-23 02:03:38 -0500 )edit

Thanks Benny for trying. The path to `/home/user/ros_catkin_ws/install_isolated/lib/` is correct. I built my ROS-Hydro from source, and installed it there.

Nap gravatar image Nap  ( 2014-04-23 02:17:20 -0500 )edit

Question Tools

1 follower


Asked: 2014-04-22 20:49:25 -0500

Seen: 1,440 times

Last updated: Apr 23 '14