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

ros/ros.h: No such file or directory after trying tutorial

asked 2021-02-08 20:11:46 -0500

littlepants gravatar image

I've gone through the c++ talker listener tutorials, copy and pasted the code and CMake files into the pkg directory and both nodes worked just fine.

I've now tried to test how well I understand the concept and have make my own package called delete_me. I have one executable called tester.cpp but catkin_make will error with ros/ros.h: No such file or directory. the following is my code and make files

tester.cpp

#include "ros/ros.h"
#include "std_msgs/String.h"

#include <sstream>

int main(int argc, char **argv)
{
    ros::init(argc, argv, "tester");

    ros::NodeHandle n;

    ROS_INFO("Hello");

    ros::spinOnce();
    return 0;
}

CMakeList.txt

cmake_minimum_required(VERSION 3.0.2)
project(delete_me)


find_package(catkin REQUIRED COMPONENTS
  roscpp
  std_msgs
)


catkin_package(
)

add_executable(tester src/tester.cpp)
target_link_libraries(tester ${catkin_LIBRARIES})

I would expect to see the onetime ros log of "Hello" then the node would end. My guess is the CMakeLists.txt file is missing something. Any advice on understanding what I'm missing would be very much appreciated.

Also if it helps I'm using Windows 10 - WSL Ubuntu 20.04 ROS-noetic

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-02-08 22:37:47 -0500

jdlangs gravatar image

You're missing the command that tells CMake where to look for C++ header files when compiling tester.cpp: either target_include_directories or include_directories. See section 7.3 in the catkin docs. It recommends using include_directories, but target_include_directories is the modern preferred style. CMake reference here.

edit flag offensive delete link more

Comments

That did it. adding include_directories(include ${catkin_INCLUDE_DIRS}) worked. Thanks for the help

littlepants gravatar image littlepants  ( 2021-02-09 18:01:52 -0500 )edit

Question Tools

Stats

Asked: 2021-02-08 20:11:46 -0500

Seen: 240 times

Last updated: Feb 08 '21