Exsample1.7 (JP) 'ros' has not been declared

user:~/catkin_ws$ catkin_make
Base path: /home/user/catkin_ws
Source space: /home/user/catkin_ws/src
Build space: /home/user/catkin_ws/build
Devel space: /home/user/catkin_ws/devel
Install space: /home/user/catkin_ws/install

Running command: “make cmake_check_build_system” in “/home/user/catkin_ws/build”

Running command: “make -j4 -l4” in “/home/user/catkin_ws/build”

[ 0%] Built target std_msgs_generate_messages_lisp
[ 0%] Built target rosgraph_msgs_generate_messages_eus
[ 0%] Built target roscpp_generate_messages_py
[ 0%] Built target std_msgs_generate_messages_py
[ 0%] Built target rosgraph_msgs_generate_messages_nodejs
[ 0%] Built target rosgraph_msgs_generate_messages_cpp
[ 0%] Built target std_msgs_generate_messages_cpp
[ 0%] Built target roscpp_generate_messages_cpp
[ 0%] Built target roscpp_generate_messages_eus
[ 0%] Built target rosgraph_msgs_generate_messages_lisp
[ 0%] Built target rosgraph_msgs_generate_messages_py
[ 0%] Built target roscpp_generate_messages_nodejs
[ 0%] Built target std_msgs_generate_messages_eus
[ 0%] Built target std_msgs_generate_messages_nodejs
[ 0%] Built target roscpp_generate_messages_lisp
[ 50%] Building CXX object my_package/CMakeFiles/simple.dir/src/simple.cpp.o
/home/user/catkin_ws/src/my_package/src/simple.cpp:1:2: error: invalid preprocessing directive #Include
#Include < ros / ros.h>
/home/user/catkin_ws/src/my_package/src/simple.cpp: In function ‘int main(int, char**)’:
/home/user/catkin_ws/src/my_package/src/simple.cpp:5:3: error: ‘ros’ has not been declared
ros::init(argc, argv, “ObiWan”);
/home/user/catkin_ws/src/my_package/src/simple.cpp:6:3: error: ‘ros’ has not been declared
ros::NodeHandle nh;
/home/user/catkin_ws/src/my_package/src/simple.cpp:7:57: error: ‘ROS_INFO’ was not declared in this scope
ROS_INFO(“Help me Obi-Wan Kenobi, you’re my only hope”);
/home/user/catkin_ws/src/my_package/src/simple.cpp:8:3: error: ‘ros’ has not been declared
my_package/CMakeFiles/simple.dir/build.make:62: recipe for target ‘my_package/CMakeFiles/simple.dir/src/simple.cpp.o’ failed
make[2]: *** [my_package/CMakeFiles/simple.dir/src/simple.cpp.o] Error 1
CMakeFiles/Makefile2:921: recipe for target ‘my_package/CMakeFiles/simple.dir/all’ failed
make[1]: *** [my_package/CMakeFiles/simple.dir/all] Error 2
Makefile:138: recipe for target ‘all’ failed
make: *** [all] Error 2
Invoking “make -j4 -l4” failed

Hi @miumama,

The errors are pointing to your c++ source file. Specifically, your “include” lines introduce some bugs:

#Include < ros / ros.h>

I can see these errors:

  • “include” should start with lowercase “i”
  • no space is allowed when specifying the header file location

So the two lines above should be:

#include <ros/ros.h>  

Please check your code again and ensure you don’t have these kinds of errors and try again.

By the way, it appears you are not very familiar with C++ yet. Perhaps you want to try the Python version of the course? If you are not familiar with Python, we have a free course that will take you through the basics of it.

1 Like