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

how to use external libraries in ROS code?

asked 2011-03-15 09:36:29 -0600

blueskin gravatar image

updated 2014-01-28 17:09:21 -0600

ngrennan gravatar image


We have a GUI that was developed using Qt and now we are planning to use ROS in our code. Is it possible to integrate ROS with our existing Qt code?

In a general sense, how do we use external libraries such as Qt, OpenGL and user built libraries with ROS code? Thank you.

edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted

answered 2011-03-16 03:01:18 -0600

updated 2017-01-01 07:45:49 -0600

lucasw gravatar image

Not in the general sense, but rather specific to your question, you can have a look at RGBD-SLAM which uses qt and opengl. The CMakeLists.txt and manifest can be found here

Check out main.cpp, qtros.h and qtros.cpp to see how we moved the ROS spinning into a subclass of QThread to run the callbacks in parallel to the Qt application's event loop.

(Update: The above links used to point to the repository which no longer exists and have been updated to point at the github rgbdslam_v2 repo which may or may not illustrate what is described)

edit flag offensive delete link more


great, this worked for qt. I changed my CMakelits.txt similar to the one in the package and it works perfectly. I am posting a small description on how to do it in the below answer.
blueskin gravatar image blueskin  ( 2011-03-16 09:00:37 -0600 )edit

answered 2011-03-15 18:41:18 -0600

KoenBuys gravatar image

For OpenGl I just add the dependency in the manifest:

    <rosdep name="opengl"/>

It is solved in the core rosdep.yaml file (rosdep wiki) My CMakelists.txt entry looks like this:

rosbuild_add_executable(${PROJECT_NAME} src/main.cpp)
target_link_libraries(${PROJECT_NAME} X11 m GL GLU glut)

In addition to the original ROS CMakelists. I assume you can do the same for QT. (if not I'm interested to know)

edit flag offensive delete link more


@KoenBuys: by specifying opengl it worked but I got undefined references for glut functions. So I also added rosdep name="glut", it didn't help. So I manually added the target_link_libraries statement with glut to my CMakelists.txt file. Do you think this will create issues in future?
blueskin gravatar image blueskin  ( 2011-03-16 02:29:13 -0600 )edit
Things like the 'opengl' above are abstractions for a package name. As koenbuys mentioned, these abstractions are converted to real package names for each distro in the rosdep.yaml files. You can find the abstraction and conversions for opengl in $ROS_ROOT/rosdep.yaml.
Daniel Stonier gravatar image Daniel Stonier  ( 2011-03-16 03:06:19 -0600 )edit
$ROS_ROOT/rosdep.yaml though is the last line of defence in trying to find the abstraction-conversion. The first rosdep.yaml any package looks in is inside the package itself, if it can't satisfy an abstraction there, it then looks in the stack rosdep.yaml, then finally $ROS_ROOT/rosdep.yaml.
Daniel Stonier gravatar image Daniel Stonier  ( 2011-03-16 03:09:12 -0600 )edit
If no abstraction exists for glut, simply create your own rosdep.yaml and put it in at your stack level (look at other stack rosdep.yaml's for examples).
Daniel Stonier gravatar image Daniel Stonier  ( 2011-03-16 03:09:49 -0600 )edit
@snorri: I did create a rosdep.yaml. I used the rosdep.yaml from geometry stack. I changed the line "ubuntu: libglut3-dev" with "ubuntu: libglut", "ubuntu: freeglut", "ubuntu: libglut3". None of them worked so I ended up changing Cmakelists.txt file
blueskin gravatar image blueskin  ( 2011-03-16 03:16:58 -0600 )edit

answered 2011-03-16 09:07:02 -0600

blueskin gravatar image

updated 2011-03-16 09:07:40 -0600

@KoenBuys answer works for OpenGL.

And as @Felix Endres suggested I was able to get Qt working with my ROS package. here's some more detail on how:

  1. edit your manifest.xml and add <rosdep name="qt4"/>
  2. edit CMakelists.txt in your package and make it look similar to CMakelists.txt

    -> the line file(GLOB_RECURSE QT_MOC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS include/local/.hpp src/mainwindow.h)* should include all the header files that use Qt functionality.

    -> the line file(GLOB_RECURSE QT_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS src/gicp-fallback.cpp src/mainwindow.cpp src/listener.cpp) should include all the cpp files that use Qt functionality.

Let me know if you have any issues. Thanks.

edit flag offensive delete link more

answered 2011-03-15 18:54:14 -0600

Daniel Stonier gravatar image

How are you currently building your qt program (e.g. qmake .pro files)? You might have to change the build system to use the cmake qt modules, but that can do everything that something like a qmake pro file can do without too much trouble and its something we've done with our qt gui's over the last six months.

Eros has some packages built from qt that you can use for illustration. Don't mind that eros is about embedded and cross-compiling, the eros_qt_tutorials package can be just as easily not cross-compiled.

It also has some python scripts to populate an ros package with the basic templates for a qt, or qt-ros program. See eros_python_tools for more information on these (roscreate-qt-pkg, roscreate-qt-ros-pkg).

edit flag offensive delete link more


@snorri: I am currently building just a makefile containing paths and rules for QT (including moc,uic). I'll look into Eros. thank you
blueskin gravatar image blueskin  ( 2011-03-16 02:04:40 -0600 )edit

Question Tools

1 follower


Asked: 2011-03-15 09:36:29 -0600

Seen: 3,398 times

Last updated: Jan 01 '17