Ask Your Question
0

fatal error: ros/ros.h: No such file or directory

asked 2018-08-11 02:45:16 -0500

Tommy Hay gravatar image

updated 2018-08-11 02:46:26 -0500

I have created a package using catkin_create_pkg on PC where I have previously installed Ubuntu 16.04 LTS and ROS kinetic. But I am trying to compile the cpp file included in the created package I get the following error

my@my-MS-7972:~/catkin_ws/src/sample_opencv/src$ g++ test_cv_bridge.cpp
test_cv_bridge.cpp:1:21: fatal error: ros/ros.h: no such file or directory
compilation terminated.

looks like it does not see any of the header files included in my cpp file.

Edit: This is what I added to my package.xml

<buildtool_depend>catkin</buildtool_depend><build_depend>cv_bridge</build_depend><build_depend>image_transport</build_depend><build_depend>roscpp</build_depend><build_depend>sensor_msgs</build_depend><build_depend>std_msgs</build_depend><build_export_depend>cv_bridge</build_export_depend><build_export_depend>image_transport</build_export_depend><build_export_depend>roscpp</build_export_depend><build_export_depend>sensor_msgs</build_export_depend><build_export_depend>std_msgs</build_export_depend><exec_depend>cv_bridge</exec_depend><exec_depend>image_transport</exec_depend><exec_depend>roscpp</exec_depend><exec_depend>sensor_msgs</exec_depend><exec_depend>std_msgs</exec_depend>

here is the Cmakelist.txt:

cmake_minimum_required(VERSION 2.8.3)
project(sample_opencv)

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

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

## Find catkin macros and libraries
## if COMPONENTS list like find_package(cat
## 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
  sensor_msgs
  std_msgs
)

find_package(OpenCV REQUIRED)

## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)


## Uncomment this if the package has a setup.py. This macro ensures
## modules and global scripts declared therein get installed
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
# catkin_python_setup()

################################################
## Declare ROS messages, services and actions ##
################################################

## To declare and build messages, services or actions from within this
## package, follow these steps:
## * Let MSG_DEP_SET be the set of packages whose message types you use in
##   your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).
## * In the file package.xml:
##   * add a build_depend tag for "message_generation"
##   * add a build_depend and a exec_depend tag for each package in MSG_DEP_SET
##   * If MSG_DEP_SET isn't empty the following dependency has been pulled in
##     but can be declared for certainty nonetheless:
##     * add a exec_depend tag for "message_runtime"
## * In this file (CMakeLists.txt):
##   * add "message_generation" and every package in MSG_DEP_SET to
##     find_package(catkin REQUIRED COMPONENTS ...)
##   * add "message_runtime" and every package in MSG_DEP_SET to
##     catkin_package(CATKIN_DEPENDS ...)
##   * uncomment the add_*_files sections below as needed
##     and list every .msg/.srv/.action file to be processed
##   * uncomment the generate_messages entry below
##   * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)

## 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
# )

################################################
## Declare ROS dynamic reconfigure parameters ##
################################################

## To declare and build dynamic reconfigure parameters within this
## package, follow these steps:
## * In the file package.xml:
##   * add a build_depend and ...
(more)
edit retag flag offensive close merge delete

Comments

1

Did you

source /opt/ros/kinetic/setup.bash
source ~/catkin_ws/devel/setup.bash

See http://wiki.ros.org/ROS/Tutorials/Ins...

lalten gravatar imagelalten ( 2018-08-11 03:36:42 -0500 )edit

I do these step ,still have same problem

Tommy Hay gravatar imageTommy Hay ( 2018-08-11 23:57:58 -0500 )edit

@PeteBlackerThe3rd is correct.

Also: this post is a duplicate of #q295301.

gvdhoorn gravatar imagegvdhoorn ( 2018-08-12 01:06:29 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-08-11 06:53:05 -0500

If you look at the Building Packages tutorial here, you need to use catkin_make to build a package (or a node within it). You're trying to use gcc with only the standard c++ headers and libraries so the compiler cannot find the ROS headers.

Since ROS is a very complex multi-language system the catkin built tool is used to automate the process.

Hope this helps.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2018-08-11 02:45:16 -0500

Seen: 399 times

Last updated: Aug 11 '18