4.2 编译你的程序包Package

对于正要马上编译自己代码的读者,请同时看一下后面的(C++)/(Python)教程 因为你可能需要修改CMakeLists.txt文件。

按照之前的创建一个ROS功能包教程,你应该已经创建好了一个catkin 工作空间 和一个名为beginner_tutorials的catkin 功能包。 现在切换到catkin workspace 并查看src文件夹:

$ cd ~/catkin_ws/
$ ls src
输出:
beginner_tutorials  CMakeLists.txt

你可以看到一个名为beginner_tutorials的文件夹,这就是你在之前的 catkin_create_pkg教程里创建的。 现在我们可以使用catkin_make来编译它了:

$ catkin_make

你可以看到很多cmake和make输出的信息:

Base path: /home/user/catkin_ws
Source space: /home/user/catkin_ws/src
Build space: /home/user/catkin_ws/build
Devel space: /home/user/catkin_ws/devel
Install space: /home/user/catkin_ws/install
####
#### Running command: "cmake /home/user/catkin_ws/src
-DCATKIN_DEVEL_PREFIX=/home/user/catkin_ws/devel
-DCMAKE_INSTALL_PREFIX=/home/user/catkin_ws/install" in "/home/user/catkin_ws/build"
####
-- The C compiler identification is GNU 4.2.1
-- The CXX compiler identification is Clang 4.0.0
-- Checking whether C compiler has -isysroot
-- Checking whether C compiler has -isysroot - yes
-- Checking whether C compiler supports OSX deployment target flag
-- Checking whether C compiler supports OSX deployment target flag - yes
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Using CATKIN_DEVEL_PREFIX: /tmp/catkin_ws/devel
-- Using CMAKE_PREFIX_PATH: /opt/ros/kinetic
-- This workspace overlays: /opt/ros/kinetic
-- Found PythonInterp: /usr/bin/python (found version "2.7.1") 
-- Found PY_em: /usr/lib/python2.7/dist-packages/em.pyc
-- Found gtest: gtests will be built
-- catkin 0.5.51
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~  traversing packages in topological order:
-- ~~  - beginner_tutorials
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ add_subdirectory(beginner_tutorials)
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/catkin_ws/build
####
#### Running command: "make -j4" in "/home/user/catkin_ws/build"
####

catkin_make首先输出它所使用到的每个空间所在的路径。

需要注意的是由于这些空间存在默认配置的原因,有几个文件夹已经在catkin工作空间自动生成了,使用ls查看:

$ ls

输出:
build
devel
src
  • build目录是build space的默认所在位置,同时cmake和make也是在这里被调用来配置并编译你的功能包。

  • devel目录是devel space的默认所在位置, 同时也是在你安装功能包之前存放可执行文件和库文件的地方。

现在我们已成功编译了一个ROS功能包,接下来我们将介绍ROS节点.

Last updated