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

fantabulum's profile - activity

2020-06-03 09:55:21 -0500 received badge  Nice Question (source)
2016-03-23 10:37:13 -0500 received badge  Famous Question (source)
2016-02-25 14:33:47 -0500 commented answer Potential Field navigation implementation in ROS ?

Link is broken

2016-02-23 14:34:46 -0500 received badge  Supporter (source)
2016-02-23 09:28:29 -0500 received badge  Enthusiast
2016-02-17 10:07:17 -0500 received badge  Scholar (source)
2016-02-17 10:07:12 -0500 answered a question Undefined reference to ros::init

Even though this was a new workspace, I created another one from scratch. In the workspace I was working in at the time, I originally had the CMakeList lines out of order. Running catkin_make clean didn't have an affect on my issue. After creating a new workspace, I copied the random_walk folder that is verbatim to what I have posted above and the problem magically vanished.

mkdir -p ~/test_space/src
cd ~/test_space/src/
catkin_init_workspace

cd ..
catkin_make
# /opt/ros/indigo/setup.bash already sourced in .bashrc
source devel/setup.bash
cp -r ~/other_wksp_path/src/random_walk ./src/
catkin_make random_walk
2016-02-17 09:57:01 -0500 commented question Undefined reference to ros::init

Maybe so. I originally had the CMakeList lines in the wrong order. I had hoped catkin_make clean would have fixed that.

2016-02-17 01:13:53 -0500 received badge  Notable Question (source)
2016-02-16 21:53:54 -0500 commented question Undefined reference to ros::init

I built a new workspace from scratch (again). I can't think of anything I did differently this time than last, but I can no longer reproduce the issue. Should this question be closed or deleted?

2016-02-16 20:50:04 -0500 commented question Undefined reference to ros::init

@lucasw I added the verbose output, not exactly sure what I'm looking for. Interesting note, this project was in a new workspace I created; I tried again in the workspace I created in the tutorials and it worked. I went back through the tutorials and have yet to find anything missing.

2016-02-16 20:48:07 -0500 received badge  Editor (source)
2016-02-15 22:35:46 -0500 received badge  Student (source)
2016-02-15 22:33:48 -0500 received badge  Popular Question (source)
2016-02-15 12:24:34 -0500 asked a question Undefined reference to ros::init

Most of the similar questions pointed to the package's CMakeList.txt . As far as I can tell, it's as it should be:

cmake_minimum_required(VERSION 2.8.3)
project(random_walk)

find_package(catkin REQUIRED COMPONENTS
 roscpp
 geometry_msgs
 sensor_msgs
)


message("catkin libraries" ${catkin_LIBRARIES})
catkin_package()

include_directories(include ${catkin_INCLUDE_DIRS})
add_executable(random_walk src/random_walk.cpp)
target_link_libraries(random_walk ${catkin_LIBRARIES})
add_dependencies(random_walk beginner_tutorials_generate_messages_cpp)

Packages.xml has the dependencies

<buildtool_depend>catkin</buildtool_depend>
<build_depend>roscpp</build_depend>
<build_depend>geometry_msgs</build_depend>
<build_depend>sensor_msgs</build_depend>
<run_depend>roscpp</run_depend>
<run_depend>geometry_msgs</run_depend>
<run_depend>sensor_msgs</run_depend>

Rosdep said all dependencies are installed. I performed a clean prior to trying to make, but I can't compile something as simple as:

#include "ros/ros.h"
int main (int argc, char **argv ) {
  ros::init(argc, argv, "random_walk");
}

Without seeing

In function main': random_walk.cpp:(.text+0x46): undefined reference toros::init(int&, char**, std::string const&, unsigned int)'

This source says "If you see errors from catkin_make that the header ros/ros.h cannot be found, or “undefined reference” errors on ros::init or other ROS functions, the most likely reason is that your CMakeLists.txt does not correctly declare a dependency on roscpp." I can't figure out what I'm missing. Any ideas?


Verbose Output of Make

/usr/bin/cmake -H/home/gary/catkin_ws/src -B/home/gary/catkin_ws/build --check-build-system CMakeFiles/Makefile.cmake 0
make -f CMakeFiles/Makefile2 random_walk
make[1]: Entering directory `/home/gary/catkin_ws/build'
/usr/bin/cmake -H/home/gary/catkin_ws/src -B/home/gary/catkin_ws/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/gary/catkin_ws/build/CMakeFiles 1
make -f CMakeFiles/Makefile2 random_walk/CMakeFiles/random_walk.dir/all
make[2]: Entering directory `/home/gary/catkin_ws/build'
make -f random_walk/CMakeFiles/random_walk.dir/build.make random_walk/CMakeFiles/random_walk.dir/depend
make[3]: Entering directory `/home/gary/catkin_ws/build'
cd /home/gary/catkin_ws/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/gary/catkin_ws/src /home/gary/catkin_ws/src/random_walk /home/gary/catkin_ws/build /home/gary/catkin_ws/build/random_walk /home/gary/catkin_ws/build/random_walk/CMakeFiles/random_walk.dir/DependInfo.cmake --color=
make[3]: Leaving directory `/home/gary/catkin_ws/build'
make -f random_walk/CMakeFiles/random_walk.dir/build.make random_walk/CMakeFiles/random_walk.dir/build
make[3]: Entering directory `/home/gary/catkin_ws/build'
Linking CXX executable /home/gary/catkin_ws/devel/lib/random_walk/random_walk
cd /home/gary/catkin_ws/build/random_walk && /usr/bin/cmake -E cmake_link_script CMakeFiles/random_walk.dir/link.txt --verbose=1
/usr/bin/c++       CMakeFiles/random_walk.dir/src/random_walk.cpp.o  -o /home/gary/catkin_ws/devel/lib/random_walk/random_walk -rdynamic /opt/ros/indigo/lib/libroscpp_serialization.so /opt/ros/indigo/lib/librostime.so -lboost_date_time /opt/ros/indigo/lib/libcpp_common.so -lboost_system -lboost_thread -lpthread -lconsole_bridge -Wl,-rpath,/opt/ros/indigo/lib 
CMakeFiles/random_walk.dir/src/random_walk.cpp.o: In function `main':
random_walk.cpp:(.text+0x46): undefined reference to `ros::init(int&, char**, std::string const&, unsigned int)'
collect2: error: ld returned 1 exit status
make[3]: *** [/home/gary/catkin_ws/devel/lib/random_walk/random_walk] Error 1
make[3]: Leaving directory `/home/gary/catkin_ws/build ...
(more)