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

Including header files in ros build system

asked 2012-04-11 03:57:52 -0500

karthik gravatar image

Hi, I have a cpp code with 3 header files for the same written by me. I want to port this code to ros including these header files in my package. I created a package with my .cpp code in src folder and changed the CMakeFile.txt to build the executable of the same. If i have to include these .h files as well to my code where do i place them in the package and how to build my code using the .h files.

Thanks, Karthik

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2012-04-11 05:04:38 -0500

joq gravatar image

updated 2012-04-11 05:05:13 -0500

The usual practice is to place your headers in include/package_name, referencing them like this:

#include <package_name/header_name.h>

You would fill in your own package_name and header_name, as appropriate.

They only need to be exported in the manifest.xml if other packages include them. Your question implies no need for that.

edit flag offensive delete link more


Thanks Joq. Ya i was missing the package_name in my include statement. It helped!!

karthik gravatar image karthik  ( 2012-04-11 05:06:46 -0500 )edit

+1 for the link to the usual practice; I always wondered if those were written down somewhere.

Mac gravatar image Mac  ( 2012-04-11 05:11:52 -0500 )edit

answered 2012-04-11 04:08:05 -0500

CaptainTrunky gravatar image


If I understand you in the right way, everything is very-very simple. You only should to place your .h in /include directory. So, .cpp files will be in yourProject/src, .hpp will be in yourProject/include. And this is all! Ros building system should to find your headers by itself, if they mentioned in your .cpp files.

edit flag offensive delete link more


Hey thanks for the response. Are you using in similar way. I did try this and it was not working so i posted this question. Could you check once and reply back.

karthik gravatar image karthik  ( 2012-04-11 05:01:25 -0500 )edit

Hey it worked!! sorry i missed as small thing. When i created a project, it happened to create /project/include/project folder where i placed my .hpp files. But when i place it back to /project/include it worked.

karthik gravatar image karthik  ( 2012-04-11 05:05:21 -0500 )edit

You can use /project/include/project method. As example, I do next: /project/include/module1...N, then in .cpp #include "moduleX/header.h"

CaptainTrunky gravatar image CaptainTrunky  ( 2012-04-11 05:13:28 -0500 )edit

Hey ya thanks! i got it from Joq's response. :)

karthik gravatar image karthik  ( 2012-04-11 05:15:49 -0500 )edit

Question Tools


Asked: 2012-04-11 03:57:52 -0500

Seen: 7,472 times

Last updated: Apr 11 '12