Akash
Akash

Reputation: 101

fatal error: ros/ros.h: No such file or directory 1 | #include "ros/ros.h"

There are a lot of questions related to this, but I could not find anything that useful to me. I created a c++ script to subscribe to a camera topic. when I tried to run the script I get the following error.

receiver.cpp:1:10: fatal error: ros/ros.h: No such file or directory
    1 | #include "ros/ros.h"
      |          ^~~~~~~~~~~

and as per I searched the internet the error is due to the CMake file. I tried various ways could not figure out why. so I have also added my CMake list file below. kindly look into it.

cmake_minimum_required(VERSION 3.0.2)
project(cv_basics)

## Compile as C++11, supported in ROS Kinetic and newer
add_compile_options(-std=c++11)

include_directories(${OpenCV_INCLUDE_DIRS})
## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
  cv_bridge
  image_transport
  roscpp
  rospy
  sensor_msgs
  std_msgs
  nav_msgs
)

## Generate messages in the 'msg' folder
# add_message_files(
#   FILES
#   Message1.msg
#   Message2.msg
# )

## Generate services in the 'srv' folder
# add_service_files(
#   FILES
#   Service1.srv
#   Service2.srv
# )

## Generate actions in the 'action' folder
# add_action_files(
#   FILES
#   Action1.action
#   Action2.action
# )

## Generate added messages and services with any dependencies listed here
#generate_messages(
 #  DEPENDENCIES
  # sensor_msgs#   std_msgs
# )



catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES cv_basics
#  CATKIN_DEPENDS cv_bridge image_transport roscpp rospy sensor_msgs std_msgs
#  DEPENDS system_lib
)

include_directories(
 include
  ${catkin_INCLUDE_DIRS}
  ${OpenCV_INCLUDE_DIRS}
)

i am using ros noetic, and ubuntu 20

Upvotes: 1

Views: 10087

Answers (1)

BTables
BTables

Reputation: 4843

You need to make sure you're building with the ros libraries in your CMakeLists.txt file. Make sure you have these lines:

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

Of course, replace some_exe and src/your_source.cpp with their correct respective names in your package.

Upvotes: 1

Related Questions