## page was copied from ROS/Tutorials/Creating a Package by Hand ## For instruction on writing tutorials ## http://www.ros.org/wiki/WritingTutorials #################################### ##FILL ME IN #################################### ## for a custom note with links: ## note = ## for the canned note of "This tutorial assumes that you have completed the previous tutorials:" just add the links ## note.0= ## descriptive title for the tutorial ## title = Creating a ROS package by hand. ## multi-line description to be displayed in search ## description = This tutorial explains how to manually create a ROS package. ## the next tutorial description (optional) ## next = ## links to next tutorial (optional) ## next.0.link= [[ROS/Tutorials/rosdep|Managing System Dependencies]] ## next.1.link= ## what level user is this tutorial for ## level= IntermediateCategory ## keywords = #################################### <> <> {{{{{#!wiki buildsystem rosbuild There is a tool for creating ROS [[Packages]] ([[roscreate|roscreate-pkg]]), but, as you will see, there is nothing actually difficult here. `roscreate-pkg` prevents mistakes and saves effort, but packages are just a directory and a simple XML file. Now we'll create a new foobar package. This tutorial assumes that we're working in the directory `pkgs` on your [[ROS/EnvironmentVariables|ROS_PACKAGE_PATH]]. {{{ pkgs$ mkdir foobar pkgs$ cd foobar }}} The very first thing we'll do is add our [[Manifest|manifest]] file. The `manifest.xml` file allows tools like [[rospack]] to determine information about what your package depends upon. Inside of `foobar/manifest.xml` put the following: {{{ A simple tutorial package Your Name Here BSD }}} Now that your package has a manifest, ROS can find it. Try executing the command: {{{ rospack find foobar }}} If ROS is set up correctly you should see something like: `/home/user/ros/pkgs/foobar`. This is how ROS finds packages behind the scenes. Note that this package now also has dependencies on [[roscpp]] and [[std_msgs]]. To see one example of why specifying these dependencies is useful, try executing the following commands [[rospack]] commands: {{{ rospack export --lang=cpp --attrib=cflags foobar rospack export --lang=cpp --attrib=lflags foobar }}} When you run these, rospack looks up the dependencies of `foobar` and generates the necessary list of includes or linking statements to compile and link the executable. These commands are used by the ROS build system to correctly compile and link your packages despite the modular nature of ROS. You'll probably never have to use these directly since our build system takes care of it for you. However, as you can see, they are reasonably easy use if you want to use a different build system. In order to take advantage of this, we need to make two build files: a `Makefile` and [[CMakeLists|CMakeLists.txt]] file. Inside of `foobar/Makefile`, put: {{{ include $(shell rospack find mk)/cmake.mk }}} This tells `make` that we're going to use CMake instead of Make to build this package. Now we need the [[CMakeLists|CMakeLists.txt]] file so that we can use CMake instead. ROS uses CMake for its more powerful flexibility when building across multiple platforms. In `foobar/CMakeLists.txt` put: {{{ cmake_minimum_required(VERSION 2.4.6) include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake) rosbuild_init() }}} That's all you need to start building a package in ROS. Of course, if you want it to actually start building something, you're going to need to learn a couple more CMake macros. See our [[CMakeLists]] guide for more information. }}}}} {{{{{#!wiki buildsystem catkin There is a tool for creating ROS [[Packages]] ([[catkin/commands/catkin_create_pkg|catkin_create_pkg]]), but, as you will see, there is nothing actually difficult here. `catkin_create_pkg` prevents mistakes and saves effort, but packages are just a directory and a simple XML file. Now we'll create a new foobar package. This tutorial assumes that we're working your catkin workspace and sourcing of the setup file is already done. {{{ catkin_ws_top $ mkdir -p src/foobar catkin_ws_top $ cd src/foobar }}} The very first thing we'll do is add our [[catkin/package.xml|manifest]] file. The `package.xml` file allows tools like [[rospack]] to determine information about what your package depends upon. Inside of `foobar/package.xml` put the following: {{{ foobar 1.2.4 This package provides foo capability. PR-foobar BSD catkin roscpp std_msgs roscpp std_msgs }}} See also [[catkin/Tutorials/CreatingPackage#ROS.2BAC8-Tutorials.2BAC8-catkin.2BAC8-CreatingPackage.Customizing_the_package.xml|this page from catkin tutorial]] for further information on [[catkin/package.xml]]. Now that your package has a manifest, ROS can find it. Try executing the command: {{{ rospack find foobar }}} If ROS is set up correctly you should see something like: `/home/user/ros/catkin_ws_top/src/foobar`. This is how ROS finds packages behind the scenes. Note that this package now also has dependencies on [[roscpp]] and [[std_msgs]]. Such dependencies are used by catkin to configure packages in the right order. Now we need the [[CMakeLists|CMakeLists.txt]] file so that [[catkin_make]], which uses CMake for its more powerful flexibility when building across multiple platforms, builds the package. In `foobar/CMakeLists.txt` put: {{{ cmake_minimum_required(VERSION 2.8.3) project(foobar) find_package(catkin REQUIRED roscpp std_msgs) catkin_package() }}} That's all you need to start building a package in ROS using `catkin`. Of course, if you want it to actually start building something, you're going to need to learn a couple more CMake macros. See our [[catkin/CMakeLists.txt|CMakeLists.txt]] guide for more information. Also always go back to beginner level tutorial ([[ROS/Tutorials/CreatingPackage|CreatingPackage]] and so on) to customize your `package.xml` and `CMakeLists.txt`. }}}}} ##ROSTutorialCategory