ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

using basic ros headers, linking error

asked 2011-06-22 08:18:28 -0500

eqzx gravatar image

updated 2011-06-23 06:16:55 -0500

I am trying to set up a custom-built ogre application that requires ogre 1.7.3, and the ogre built into ros does not contain the definitions needed. So I have customized the CMakeLists.txt file of a package I am creating, and when trying to use the listener and talker functionality as mentioned in the tutorials, I get a bunch of compiling errors like this one (all 'undefined references'):

/opt/ros/diamondback/stacks/ros_comm/clients/cpp/roscpp/include/ros/node_handle.h:208: undefined reference to ros::NodeHandle::advertise(ros::AdvertiseOptions&)'

which corresponds to this line of code: ros::Publisher chatter_pub = n.advertise<std_msgs::String>("chatter",1000);

And Here is my cmake file (sorry, not allowed to attach it)

cmake_minimum_required(VERSION 2.4.6)

set(CMAKE_MODULE_PATH "/usr/local/lib/OGRE/cmake/") 

find_package(OIS REQUIRED)
find_package(OGRE REQUIRED)
if (OGRE_Terrain_FOUND)
  message(STATUS "Found OGRE_Terrain: ${OGRE_Terrain_LIBRARIES}")
else (OGRE_Terrain_FOUND)
  message(SEND_ERROR "OgreTerrain Library not found.")



file(MAKE_DIRECTORY ./bin)
file(MAKE_DIRECTORY ./media)

set(Boost_ADDITIONAL_VERSIONS "1.44" "1.44.0" "1.42" "1.42.0" "1.41.0" "1.41" "1.40.0" "1.40" 
"1.39.0" "1.39" "1.38.0" "1.38" "1.37.0" "1.37" )

set(OGRE_BOOST_COMPONENTS thread date_time)
rosbuild_add_library(${PROJECT_NAME} ./src/sim1.cpp)
rosbuild_add_library(${PROJECT_NAME} ./src/BaseApplication.cpp)
target_link_libraries(${PROJECT_NAME} ${LIBS})
rosbuild_add_executable(${PROJECT_NAME} ${HDRS} ${SRCS}) 

Here is the specific compilation command of running rosmake verbosely

/usr/bin/cmake -E cmake_link_script CMakeFiles/Sim1.dir/link.txt --verbose=1 /usr/bin/c++ -O2 -g -pthread -pthread -pthread CMakeFiles/Sim1.dir/src/sim1.o CMakeFiles/Sim1.dir/src/BaseApplication.o -o bin/Sim1 -rdynamic -L/opt/ros/diamondback/stacks/ros_comm/clients/cpp/roscpp/lib -L/opt/ros/diamondback/stacks/ros_comm/clients/cpp/roscpp_serialization/lib -L/opt/ros/diamondback/stacks/ros_comm/utilities/xmlrpcpp/lib -L/opt/ros/diamondback/stacks/ros_comm/tools/rosconsole/lib -L/opt/ros/diamondback/stacks/ros_comm/utilities/rostime/lib -L/opt/ros/diamondback/stacks/ros_comm/utilities/cpp_common/lib -L/opt/ros/diamondback/ros/core/roslib/lib -L/opt/ros/diamondback/ros/tools/rospack/lib -lOIS /usr/local/lib/ /usr/local/lib/ -lboost_thread-mt

...continued(these next lines are all one line)

-Wl,-rpath,/opt/ros/diamondback/stacks/ros_comm/clients/cpp/roscpp/lib: /opt/ros/diamondback/stacks/ros_comm/clients/cpp/roscpp_serialization/lib: /opt/ros/diamondback/stacks/ros_comm/utilities/xmlrpcpp/lib: /opt/ros/diamondback/stacks/ros_comm/tools/rosconsole/lib: /opt/ros/diamondback/stacks/ros_comm/utilities/rostime/lib: /opt/ros/diamondback/stacks/ros_comm/utilities/cpp_common/lib: /opt/ros/diamondback/ros/core/roslib/lib:/opt/ros/diamondback/ros/tools/rospack/lib: /usr/local/lib

Solved: I took the advice of ... (more)

edit retag flag offensive close merge delete


Try formatting your Cmakefile using the code tag. That will make it much more readable.
Asomerville gravatar image Asomerville  ( 2011-06-22 09:39:44 -0500 )edit

2 Answers

Sort by » oldest newest most voted

answered 2011-06-22 08:34:28 -0500

updated 2011-06-22 11:27:57 -0500

An undefined reference is almost always a missing library in the link step. Just shooting in the dark, I would guess you're missing a dependency on "roscpp" in your manifest.xml

running rosmake with:

VERBOSE=1 rosmake -v

Will print the exact lines used to compile and link. You could then verify one way or another that the library was linked in. In some way or another, roslib is not being linked in.

Your CMakeLists.txt is way more complicated than it probably should be. Some of the default ros stuff is probably getting undone in one of your sets. Try simplifying.

edit flag offensive delete link more


unfortunately, I tried that already
eqzx gravatar image eqzx  ( 2011-06-22 08:49:40 -0500 )edit
try with verbose to show compile commands
Asomerville gravatar image Asomerville  ( 2011-06-22 09:11:53 -0500 )edit
okay. roscpp looks like it's in there...I updated the question with the output
eqzx gravatar image eqzx  ( 2011-06-22 09:30:26 -0500 )edit
I see the directory, but not the lib itself. It looks like you're missing '`-lroslib`' at the very least.
Asomerville gravatar image Asomerville  ( 2011-06-22 09:38:37 -0500 )edit
I added that to the manifest as well, still didn't help. the compilation for the tutorial gives the impression that linking with ros is a few short lines...
eqzx gravatar image eqzx  ( 2011-06-22 10:12:23 -0500 )edit
Your CmakeLists.txt is way more complicated than any I've created. I suspect you're borking the default ros stuff somewehere in there with one or more of your sets
Asomerville gravatar image Asomerville  ( 2011-06-22 11:21:16 -0500 )edit
I would agree with that suspicion. I think its best to approach from the other side: Create a package with standard ros tools and write a working listener/publisher - then add the OGRE stuff
dornhege gravatar image dornhege  ( 2011-06-22 22:27:12 -0500 )edit
thank you guys. i took your advice dornhege, finally compiles now.
eqzx gravatar image eqzx  ( 2011-06-23 06:12:48 -0500 )edit

answered 2011-06-23 00:27:15 -0500

Does your cpp source (or header) file have the following line?

#include <ros.h>
edit flag offensive delete link more


yes, I use #include <ros/ros.h> (compiler can't find header using #include <ros.h>)
eqzx gravatar image eqzx  ( 2011-06-23 03:05:07 -0500 )edit

Your Answer

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

Add Answer

Question Tools


Asked: 2011-06-22 08:18:28 -0500

Seen: 2,136 times

Last updated: Jun 23 '11