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

fatal error: beginner_tutorials/AddTwoInts.h: No such file or directory , #include "beginner_tutorials/AddTwoInts.h"

asked 2015-07-12 23:24:14 -0500

mayankfirst gravatar image

updated 2017-01-13 02:13:38 -0500

NEngelhard gravatar image
/home/mayankfirst/catkin_ws/src/beginner_tutorials/src/add_two_ints_client.cpp:2:43: fatal error: beginner_tutorials/AddTwoInts.h: No such file or directory
 #include "beginner_tutorials/AddTwoInts.h"
                                           ^
compilation terminated.
/home/mayankfirst/catkin_ws/src/beginner_tutorials/src/add_two_ints_server.cpp:2:43: fatal error: beginner_tutorials/AddTwoInts.h: No such file or directory
 #include "beginner_tutorials/AddTwoInts.h"
                                           ^
compilation terminated.
make[2]: *** [beginner_tutorials/CMakeFiles/add_two_ints_client.dir/src/add_two_ints_client.cpp.o] Error 1
make[2]: Leaving directory `/home/mayankfirst/catkin_ws/build'
make[1]: *** [beginner_tutorials/CMakeFiles/add_two_ints_client.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
make[2]: *** [beginner_tutorials/CMakeFiles/add_two_ints_server.dir/src/add_two_ints_server.cpp.o] Error 1
make[2]: Leaving directory `/home/mayankfirst/catkin_ws/build'
make[1]: *** [beginner_tutorials/CMakeFiles/add_two_ints_server.dir/all] Error 2
make[1]: Leaving directory `/home/mayankfirst/catkin_ws/build'
make: *** [all] Error 2
Invoking "make -j4 -l4" failed

#############################################################################################

CMAKE list

cmake_minimum_required(VERSION 2.8.3)
project(beginner_tutorials)

## 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
  roscpp
  rospy
  std_msgs
  genmsg
)

## 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 and a run_depend tag for each package in MSG_DEP_SET
##   * If MSG_DEP_SET isn't empty the following dependencies might have been
##     pulled in transitively but can be declared for certainty nonetheless:
##     * add a build_depend tag for "message_generation"
##     * 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_message_files(DIRECTORY msg FILES Num.msg)
add_service_files(DIRECTORY srv FILES AddTwoInts.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)

###################################
## 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(CATKIN_DEPENDS roscpp rospy std_msgs genmsg)
#  INCLUDE_DIRS include
#  LIBRARIES beginner_tutorials
#  CATKIN_DEPENDS roscpp rospy std_msgs
#  DEPENDS system_lib
#)

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

## Specify additional locations ...
(more)
edit retag flag offensive close merge delete

Comments

3

Please post your CMakeLists.txt

BennyRe gravatar image BennyRe  ( 2015-07-13 02:13:36 -0500 )edit

...and the workspace layout.

dornhege gravatar image dornhege  ( 2015-07-13 03:29:14 -0500 )edit

5 Answers

Sort by ยป oldest newest most voted
2

answered 2015-07-15 01:54:12 -0500

ahendrix gravatar image

It looks like the headers for your service files are not being generated before the programs that use them are compiled.

You can declare this build dependency using the add_dependencies() cmake command. Try adding the following to your CMakeLists.txt:

add_dependencies(add_two_ints_server ${beginner_tutorials_EXPORTED_TARGETS})
add_dependencies(add_two_ints_client ${beginner_tutorials_EXPORTED_TARGETS})
edit flag offensive delete link more

Comments

But even after adding the above dependencies it gives the same error

mayankfirst gravatar image mayankfirst  ( 2015-07-15 04:23:34 -0500 )edit

There may be some problem in SRV when I try to execute rossrv show beginner_tutorials/AddTwoInts It gives the following message Unknown srv type [beginner_tutorials/AddTwoInts]: Cannot locate message [AddTwoInts]: unknown package [beginner_tutorials] on search path [{'rosconsole': ['/opt/ros/ind

mayankfirst gravatar image mayankfirst  ( 2015-07-15 05:50:47 -0500 )edit

it looks like your rossrv show error is because you haven't sourced your workspace.

ahendrix gravatar image ahendrix  ( 2015-07-15 15:57:29 -0500 )edit

Sir, I do not have rossrv show error. I am having the compilation error and getting the following message fatal error: beginner_tutorials/AddTwoInts.h: No such file or directory #include "beginner_tutorials/AddTwoInts.h

mayankfirst gravatar image mayankfirst  ( 2015-07-18 01:39:08 -0500 )edit

I have also sourced my workspace using . ~/catkin_ws/devel/setup.bash

mayankfirst gravatar image mayankfirst  ( 2015-07-18 01:41:12 -0500 )edit

I added what you suggested and I get:

 -- Using these message generators: gencpp;genlisp;genpy
    -- beginner_tutorial: 1 messages, 1 services
    CMake Error at beginner_tutorial/CMakeLists.txt:182 (add_dependencies):
      add_dependencies called with incorrect number of arguments
UserK gravatar image UserK  ( 2015-08-10 09:42:56 -0500 )edit
1

@UserK: It looks like your variable name and your package name don't match; your package name is beginner_tutorial but the variable name you're using is beginner_tutorials.

ahendrix gravatar image ahendrix  ( 2015-08-10 22:44:54 -0500 )edit

It would be great to have ompl renamed. These warning msgs keep popping up, even in rqt_graph. argsl

~/catkin_ws1/bags$ WARNING: Package "ompl" does not follow the version conventions. It should not contain leading zeros (unless the number is 0).
WARNING: Package "ompl" does not follow...
user23fj239 gravatar image user23fj239  ( 2016-04-27 16:14:37 -0500 )edit
2

answered 2017-01-12 15:14:46 -0500

MuratAhmetGenc gravatar image

the same error. but in my case, I forgot the following change in the CMakeList.txt;

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

once I did it, catkin_make worked fine.

edit flag offensive delete link more
1

answered 2016-03-18 11:46:52 -0500

tekin gravatar image

I had the same problem and I solved It by doing a previous tutorial. The file "beginner_tutorials/AddTwoInts.h" is created in tutorial "Creating a ROS msg and srv".

edit flag offensive delete link more

Comments

I have gone through "Creating a ROS msg and srv" tutorial but I didn't get how to build this .h header file. Can you explain here, how you did it?

Pikachu gravatar image Pikachu  ( 2016-06-16 01:50:07 -0500 )edit

I think the error is probably because you might not have compiled the srv with catkin to generate the header file 'AddTwoInts.h'. Simply comment out any additional code for adding executable, dependencies or library links in CMakeLists.txt & run 'catkin_make install'. Now uncomment and 'catkin_make'

raghunitin gravatar image raghunitin  ( 2016-07-26 07:07:53 -0500 )edit
0

answered 2022-05-09 00:41:25 -0500

sajid1122 gravatar image

As for me add_service_files( FILES AddTwoInts.srv ) I forgot to add this. They told us to add this in the tutorial.

edit flag offensive delete link more
0

answered 2019-10-17 00:29:18 -0500

Nicye gravatar image

In official tutorial, http://wiki.ros.org/ROS/Tutorials/Cre... Follow this paragraph:

Any .msg file in the msg directory will generate code for use in all supported languages. The C++ message header file will be generated in ~/catkin_ws/devel/include/beginner_tutorials/. The Python script will be created in ~/catkin_ws/devel/lib/python2.7/dist-packages/beginner_tutorials/msg. The lisp file appears in ~/catkin_ws/devel/share/common-lisp/ros/beginner_tutorials/msg/.

So,you need look up your directory , in ~/catkin_ws/devel/include/beginner_tutorials/. for c ++ ,in ~/catkin_ws/devel/lib/python2.7/dist-packages/beginner_tutorials/msg. for python . And do not forget to change the directory "xx/xx" in cpp file to correct directory .

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-07-12 23:24:14 -0500

Seen: 12,254 times

Last updated: May 09 '22