Failing to include header files from packA/include/packA/ in packA and packB

asked 2019-11-25 01:27:14 -0500

romanocarv gravatar image

Hello guys, i wrote a .cpp and a .h file containing a function that should be used by multiple nodes.

test.cpp

#include <test.h>

float addAB(float a, float b) {

    float r;    

    r = a + b;

    return r;

}

test.h

float addAB(float a, float b);

I have 2 roscpp packages: packA and packB, with the nodes packA_node.cpp and packB_node.cpp.

test.cpp and test.h are inside /packA/include/packA/

Now i want them to be used by both packA_node.cpp and packB_node.cpp

I tried including them as #include <test.h>, #include "test.h" and #include <packa include="" packa="" test.h="">, but none of them work. The header file test.h cant be found.

CMakeLists packA

cmake_minimum_required(VERSION 2.8.3)
project(packA)

## 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(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
  geometry_msgs
  nav_msgs
  roscpp
  std_msgs
)

## 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
#   geometry_msgs#   nav_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 a exec_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 ...
(more)
edit retag flag offensive close merge delete

Comments

1

Please remove all the boilerplate comments from the CMakeLists.txt you show.

About 95% of those lines could be deleted, and we would only be missing comments.

gvdhoorn gravatar image gvdhoorn  ( 2019-11-25 03:30:17 -0500 )edit
1

Also: there are quite a few older Q&As about this. Searching with Google (include header other package site:answers.ros.org) leads me to #q201977, #q285472, #q279929, #q249055, #q54010 and many others.

Could you try searching yourself and tell us whether any of the older Q&As clear things up for you?

I read many different topics an tried different approaches, but none of them worked.

then please tell us what you have read and tried, so we don't end up suggesting the same things.

gvdhoorn gravatar image gvdhoorn  ( 2019-11-25 03:34:53 -0500 )edit