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

Is it possible to have a header file for a node?

asked 2015-11-02 04:30:18 -0500

ROSexperimentin gravatar image

I'm writing a ROS node in C++. I wanted to know if it's possible to have a .h file (in addition to the .cpp file that includes the node's code) for it. The .h file includes just a bunch of other #include-s, a typedef command, and the declaration of all the functions used by the node. This way the .cpp file only has an #include for its .h file. So, is it possible to do that? And what do I need to add to my CMakeLists.txt to make it compile?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-11-02 05:27:45 -0500

BennyRe gravatar image

Yes this is possible. You use roscpp, so you can use all aspects of C++. In your CMakeLists.txt you have to make sure that your include directory is listed in the include_directories section.

edit flag offensive delete link more


and that's it? no need to explicitly add the .h file in the add_executable section (or is that just a wrong way to add .h files anyway?)

ROSexperimentin gravatar image ROSexperimentin  ( 2015-11-02 05:55:00 -0500 )edit

No that's it. The compiler will search it's include path for the include files.

BennyRe gravatar image BennyRe  ( 2015-11-02 06:27:41 -0500 )edit

Question Tools

1 follower


Asked: 2015-11-02 04:30:18 -0500

Seen: 840 times

Last updated: Nov 02 '15