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

catkin_make fails when linking on reference to ros::NodeHandle

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

Nap gravatar image

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

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:

/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 ... (more)

edit retag flag offensive close merge delete

Comments

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 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
0

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

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
1

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

BennyRe gravatar image

Uncomment the CATKIN_DEPENDS line in

catkin_package(
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

Comments

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

Nap gravatar image Nap  ( 2014-04-22 22:54:16 -0600 )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 -0600 )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 -0600 )edit

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

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

Question Tools

1 follower

Stats

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

Seen: 1,462 times

Last updated: Apr 23 '14