0
$\begingroup$

Rosanswers logo

I have created a package using catkin_create_pkg on my raspberry pi 3 where I have previously installed Ubuntu Xenial and ROS kinetic. But everytime I am trying to compile the cpp file included in the created package I get the following error

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.

I have all set up the same way on my other computer running ubuntu Trusty and ROS indigo. Not sure why this is happening here.

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

  <build_depend>roscpp</build_depend>
  <build_depend>rospy</build_depend>
  <build_depend>std_msgs</build_depend>
  <build_depend>geometry_msgs</build_depend>
  <build_depend>message_generation</build_depend>

  <run_depend>roscpp</run_depend>
  <run_depend>rospy</run_depend>
  <run_depend>std_msgs</run_depend>
  <run_depend>geometry_msgs</run_depend>
  <run_depend>message_runtime</run_depend>

here is the Cmakelist.txt:

cmake_minimum_required(VERSION 2.8.3)
project(sphero_move)

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

include_directories(${catkin_INCLUDE_DIRS})

## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)
find_package(catkin REQUIRED COMPONENTS 
  roscpp
  rospy
  std_msgs
  geometry_msgs
  message_generation
)

## 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 run_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 run_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
#   std_msgs  # Or other packages containing 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 a run_depend tag for "dynamic_reconfigure"
## * In this file (CMakeLists.txt):
##   * add "dynamic_reconfigure" to
##     find_package(catkin REQUIRED COMPONENTS ...)
##   * uncomment the "generate_dynamic_reconfigure_options" section below
##     and list every .cfg file to be processed

## Generate dynamic reconfigure parameters in the 'cfg' folder
# generate_dynamic_reconfigure_options(
#   cfg/DynReconf1.cfg
#   cfg/DynReconf2.cfg
# )

###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if you package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES sphero_move
CATKIN_DEPENDS roscpp rospy std_msgs geometry_msgs message_runtime
#  DEPENDS system_lib
)

###########
## Build ##
###########

## Specify additional locations of header files
## Your package locations should be listed before other locations
# include_directories(include)

## Declare a C++ library
# add_library(sphero_move
#   src/${PROJECT_NAME}/sphero_move.cpp
# )

## Add cmake target dependencies of the library
## as an example, code may need to be generated before libraries
## either from message generation or dynamic reconfigure
# add_dependencies(sphero_move ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

## Declare a C++ executable
add_executable(robot_move_node src/robot_move.cpp)

## Add cmake target dependencies of the executable
## same as for the library above
# add_dependencies(sphero_move_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

## Specify libraries to link a library or executable target against
target_link_libraries(robot_move_node
   ${catkin_LIBRARIES}
 )

add_dependencies(robot_move_node beginner_tutorials_gencpp)

#############
## Install ##
#############

# all install targets should use catkin DESTINATION variables
# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html

## Mark executable scripts (Python etc.) for installation
## in contrast to setup.py, you can choose the destination
# install(PROGRAMS
#   scripts/my_python_script
#   DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )

## Mark executables and/or libraries for installation
# install(TARGETS sphero_move sphero_move_node
#   ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
#   LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
#   RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )

## Mark cpp header files for installation
# install(DIRECTORY include/${PROJECT_NAME}/
#   DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
#   FILES_MATCHING PATTERN "*.h"
#   PATTERN ".svn" EXCLUDE
# )

## Mark other files for installation (e.g. launch and bag files, etc.)
# install(FILES
#   # myfile1
#   # myfile2
#   DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
# )

#############
## Testing ##
#############

## Add gtest based cpp test target and link libraries
# catkin_add_gtest(${PROJECT_NAME}-test test/test_sphero_move.cpp)
# if(TARGET ${PROJECT_NAME}-test)
#   target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
# endif()

## Add folders to be run by python nosetests
# catkin_add_nosetests(test) 

and here is how Im including my header files

#include "ros/ros.h"
#include "geometry_msgs/Twist.h"
#include 

Originally posted by aldolereste on ROS Answers with karma: 53 on 2016-06-20

Post score: 4


Original comments

Comment by gvdhoorn on 2016-06-20:
Without seeing at least your CMakeLists.txt and package.xml this is going to be difficult to diagnose. Please include a copy of those files (without all the boilerplate comments) in your question. Use the edit button/link for that, and the Preformatted text button to format them.

Comment by gvdhoorn on 2016-06-20:
I don't see a include_directories(${catkin_INCLUDE_DIRS}) anywhere in your snippet (is that the whole file?). Without that, any #include .. of ROS related files will fail with the error you mentioned.

Comment by Pablo Iñigo Blasco on 2016-06-20:
right, that idea that gvdhoorn says looks good

Comment by aldolereste on 2016-06-21:
Just included it and edited the question above with the full content of my CMakeLists.txt file. No success so far

Comment by gvdhoorn on 2016-06-21:
For future questions: please don't include all the comments whenever you post a CMakeLists.txt: they are completely unnecessary, and make it harder to spot problems.

$\endgroup$

3 Answers 3

0
$\begingroup$

Rosanswers logo

From your CMakeLists.txt this appears to be more of a CMake problem than really ROS related, but:

cmake_minimum_required(VERSION 2.8.3)
project(sphero_move)
...
find_package(catkin REQUIRED)
include_directories(${catkin_INCLUDE_DIRS})
find_package(catkin REQUIRED COMPONENTS 
  ...
) 

This is your problem: you find_package(..) the catkin package twice. As with other CMake libraries, the second will not necessarily overwrite the first, so it never really does what you want.

Apart from that, you invoke include_directories(..) before your call to find_package(catkin ..) which actually finds the ROS packages you are interested in, and are using. At that point, catkin_INCLUDE_DIRS is empty, leading to no changes to the header search path and ultimately the errors you see.

I'd suggest to merge the two find_package(catkin ..) calls, keep the COMPONENTS and its arguments, and place the include_directories(..) line after find_package(catkin ..) has had a chance to find your dependencies and populate the variable.

Some references: catkin/CMakeLists.txt on the ROS wiki, and catkin 0.6.18 documentation » How to do common tasks » Package format 2 (recommended) in the Catkin docs (Indigo version). For the second link, see the C++ catkin library dependencies and C++ system library dependencies sections.


Originally posted by gvdhoorn with karma: 86574 on 2016-06-21

This answer was ACCEPTED on the original site

Post score: 15


Original comments

Comment by aldolereste on 2016-06-23:
That worked. Thanks

Comment by Ahmed Ayman on 2021-04-19:
i have the same issue but my CMakeLists seems fine. i am using ros noetic

$\endgroup$
0
$\begingroup$

Rosanswers logo

I had this error with a package that compiled fine in Jade but not Kinetic, it turned out I had spelled catkin_INCLUDE_DIRS wrong. I think pre-Kinetic includes from every package in a workspace were commingled (so the correctly spelled included in a previously processed package got the includes in).


Originally posted by lucasw with karma: 8729 on 2017-06-01

This answer was NOT ACCEPTED on the original site

Post score: 4

$\endgroup$
0
$\begingroup$

Rosanswers logo

Using Ubuntu Xenial and Kinetic Kame, I'm going through the tutorials and right now I'm at "Writing Service&Client" part. When I tried to catkin_make the project, I got the same problem, however none of the above mentioned solutions worked for me. Here is my CMakeList.txt:

cmake_minimum_required(VERSION 2.8.3)
project(beginner_tutorials)

find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs genmsg)

add_message_files(FILES Num.msg)
add_service_files(FILES AddTwoInts.srv)

generate_messages(DEPENDENCIES std_msgs)

catkin_package()
include_directories(include ${catkin_INCLUDE_DIRS})

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

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

add_executable(add_two_ints_server src/add_two_ints_server.cpp)
target_link_libraries(add_two_ints_server ${catkin_LIBRARIES})
add_dependencies(add_two_ints_server beginner_tutorials_gencpp)

add_executable(add_two_ints_client src/add_two_ints_client.cpp)
target_link_libraries(add_two_ints_client ${catkin_LIBRARIES})
add_dependencies(add_two_ints_client beginner_tutorials_gencpp)

Nothing seems wrong to me (in fact the file is exactly this, without the comments), however I may be missing something.


Originally posted by cydonia with karma: 11 on 2017-07-06

This answer was NOT ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.