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

Incorporating ROS without using catkin for C++ projects

asked 2020-11-13 07:34:32 -0500

CroCo gravatar image

I've done reading the ROS tutorials for beginners. What I would like to do next is to use ROS classes inside my C++ projects. I usually use Qt for this matter. ROS heavily uses catkin tools which prevents me from easily incorporating its tools inside other C++ projects. How can I smartly mix CMakeLists generated by catkin to CMakeLists generated by Qt? I would like to use talker/listener example in GUI in Qt framework. Also, how can I know the dependencies of ROS for C++ projects? Any suggestions?

edit retag flag offensive close merge delete



I'm not sure this is what the OP is looking for, but the go-to answer for "can I build ROS nodes without using Catkin" is typically a reference to gerkey/ros1_external_use.

And as a result of this discussion on ROS Discourse, @gerkey added the Writing a Simple Publisher and Subscriber (C++) (plain cmake) tutorial to the ROS wiki.

This might also provide some insight.

gvdhoorn gravatar image gvdhoorn  ( 2020-11-13 10:06:07 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2020-11-13 10:22:25 -0500

Root3287 gravatar image

updated 2020-11-13 10:38:14 -0500


I had the same issue that you had. What I found is that ROS has all their C++ libraries under /opt/ros/[version]/lib. What you need to link to get ROS working is roscpp, rostime, rosconsole, roscpp_serialization, and boost_system. Include the ros headers to your project. They are under /opt/ros/[version]/include.

To make ROS recognize that you have a project place an xml file called package.xml and load it the basic data for it to work. Then you need to set a ROS package path to the directory above the project root.

For example if your project is under ~/git/my_ros_project you need to have the ROS_PACKAGE_PATH environment variable set to export ROS_PACKAGE_PATH=~/git:$ROS_PACKAGE_PATH. Then under the ~/git/my_ros_project you need an project.xml file.

You can checkout my repository for a relative decent template structure if you need help. Then look into the premake5.lua file and see how the project is set up. All that is currently missing is generating MSG and SRV files which could be generated by the rosrun gencpp command.

I hope this helps!

Edit 1: From the comments, if you installed ROS anywhere else, you need to change the /opt/ros to where ever you installed ros. Check comments.

edit flag offensive delete link more


While this is great, please do add this works for packages which have been installed in /opt/ros. Not for packages in user workspaces, or any other overlays.

gvdhoorn gravatar image gvdhoorn  ( 2020-11-13 10:26:24 -0500 )edit

answered 2020-11-13 09:00:49 -0500

JackB gravatar image

updated 2020-11-13 10:05:26 -0500

EDIT: Don't use rosbuild per @gvdhoorn 's comment below

This is not my area of expertise, but check rosbuild out.

This isn't the place for a tutorial, but a project I work on, that use CMake, and builds ROS nodes, but avoids catkin, roughly uses these commands:



The link to the repo's CMakeLists.txt is here.


edit flag offensive delete link more


@JackB: please don't recommend anyone to use rosbuild. It's the precursor to Catkin, and heavily deprecated since at least Groovy. See also the notice on the wiki/rosbuild page.

I would also not recommend you use it yourself.

To the OP: Catkin does not generate anything, certainly not any CMakeLists.txt. It's all CMake. Only thing Catkin adds is a bunch of CMake macros and functions.

gvdhoorn gravatar image gvdhoorn  ( 2020-11-13 09:51:26 -0500 )edit

Ok thanks for the feedback, not an expert here as mentioned. I am still curious to hear the answer to the question: "best way to ROSify something without using Catkin"

JackB gravatar image JackB  ( 2020-11-13 10:03:55 -0500 )edit

I feel some nuance is in order.

Catkin really doesn't add anything special. It's all convenience.

Without it, you'll mostly just be copy-pasting lots of boilerplate CMake code.

For a rough idea, look at how CMakeLists.txt in ROS 2 look, with the myriad of find_package(..) and target_link_libraries(..). That's basically what Catkin does for you (plus a little more which has to do with generating CMake config files and .pc files).

gvdhoorn gravatar image gvdhoorn  ( 2020-11-13 10:16:14 -0500 )edit

That makes a lot of sense, thank you!

JackB gravatar image JackB  ( 2020-11-13 10:23:42 -0500 )edit

Question Tools



Asked: 2020-11-13 07:34:32 -0500

Seen: 493 times

Last updated: Nov 13 '20