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

Revision history [back]

click to hide/show revision 1
initial version

In theory, this should be doable. In practice, there will be lots of caveats that make annoying to non-ros users.

If you compile your project with cmake, you should be able to compile against roscpp and sensor_msgs by doing something like this in your CMakeLists.txt:

find_package(roscpp REQUIRED)
find_package(sensor_msgs REQUIRED)

include_directories(${roscpp_INCLUDE_DIRS} ${sensor_msgs_INCLUDE_DIRS})

add_executable(my_program my_program.cpp)
target_link_libraries(my_program ${roscpp_LIBRARIES} ${sensor_msgs_LIBRARIES})

If you compile with something other than CMake, you can probably use pkgconfig to find the compile and link flags for roscpp. This is mostly beyond the scope of my experience, and is probably not well tested.

Caveats include, but may not be limited to:

  • You need to have ROS installed and sourced in order to build this, because it relies on the CMAKE_PREFIX_PATH set by the ROS setup in order to find the roscpp and sensor_msgs libraries
  • You need to have ROS installed and sourced in order to run the final executable, because your program will be dynamically linked against roscpp, and will require the LD_LIBRARY_PATH set by the ROS setup in order to find the dynamic library for ROS

You may be able to get around these with static linking, or by detecting when ROS is not found, and compiling without it.