Skip to content

Instantly share code, notes, and snippets.

@gerkey
Last active February 19, 2016 16:10
Show Gist options
  • Save gerkey/1f1187bce077ba6e737a to your computer and use it in GitHub Desktop.
Save gerkey/1f1187bce077ba6e737a to your computer and use it in GitHub Desktop.
ROS 1 message reuse
cmake_minimum_required(VERSION 2.8.3)
find_package(sensor_msgs REQUIRED)
include_directories(${sensor_msgs_INCLUDE_DIRS})
link_directories(${sensor_msgs_LIBRARY_DIRS})
add_executable(foo foo.cpp)
target_link_libraries(foo ${sensor_msgs_LIBRARIES})
#include <sensor_msgs/LaserScan.h>
#include <stdio.h>
int
main(void)
{
sensor_msgs::LaserScan scan;
for(int i=0; i<100; i++)
scan.ranges.push_back(42.0*i);
for(std::vector<float>::const_iterator it = scan.ranges.begin();
it != scan.ranges.end();
++it)
printf("%f\n", *it);
}
sudo apt-get install ros-indigo-sensor-msgs
# cd to directory with CMakeLists.txt and foo.cpp
export CMAKE_PREFIX_PATH=/opt/ros/indigo:$CMAKE_PREFIX_PATH
mkdir build
cd build
cmake ..
make
@wjwwood
Copy link

wjwwood commented Feb 18, 2016

The link_directories line is probably unnecessary.

@gerkey
Copy link
Author

gerkey commented Feb 19, 2016

Thanks for the tip; it turns out that target_link_libraries can also be skipped, at least in my minimal testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment