ros/ros.h: No such file or directory after trying tutorial
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
Asked by littlepants on 2021-02-08 21:11:46 UTC
Answers
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.
Asked by jdlangs on 2021-02-08 23:37:47 UTC
Comments
That did it. adding include_directories(include ${catkin_INCLUDE_DIRS})
worked.
Thanks for the help
Asked by littlepants on 2021-02-09 19:01:52 UTC
Comments