http://blog.csdn.net/zyh821351004/article/details/50388429

1.  catkin_make 与cmake的关系

程序在cmake编译的流程: cmake指令依据你的CMakeLists.txt 文件,生成makefiles文件,make再依据此makefiles文件编译链接生成可执行文件.

catkin_make是将cmake与make的编译方式做了一个封装的指令工具, 规范了工作路径与生成文件路径.

1)  cmake标准流程

 $ mkdir build
$ cd build
$ cmake ..
$ make
$ make install # (可选)

2) catkin_make 的流程

# In a catkin workspace  
$ catkin_make
$ catkin_make install # (可选)
如果源码不在默认工作空间,需要指定编译路径:  

# In a catkin workspace
$ catkin_make --source my_src
$ catkin_make install --source my_src # (optionally)

2. catkin_make

1) catkin_make默认的路径信息

catkin_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 #catkin_make 封装运行中cmake运行的情况
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" #编译工具查找
-- Using CATKIN_DEVEL_PREFIX: /tmp/catkin_ws/devel
-- Using CMAKE_PREFIX_PATH: /opt/ros/groovy
-- This workspace overlays: /opt/ros/groovy #编译的包
<pre name="code" class="cpp">#catkin_make 封装运行中make运行的情况

#### Running command: "make -j4" in "/home/user/catkin_ws/build"

2)  layout :ros工作空间文件系统结构

    workspace_folder/        --WORKSPACE  工作空间
src/ --SOURCE SPACE 源空间
CMakeLists.txt/ --This is symlinked to catkin/cmake/toplevel.cmake
package_1/
CMakeLists.txt
package.xml
...
package_n/
CMakeLists.txt
package.xml
build/ --BUILD SPACE 编译空间 (this is where build system is invoked, not necessarily within workspace)
CATKIN_IGNORE --Marking the folder to be ignored when crawling for packages (necessary when source
space is in the root of the workspace, the file is emtpy)
#此选项可用于忽略某个包编译
devel/ --DEVEL SPACE 开发空间(targets go here, parameterizable, but defaults to peer of Build Space)
# 生成二值 库 可执行文件
bin/
etc/
/include/
lib/
share/
.catkin --Marking the folder as a development space (the file contains a semicolon separated list of Source space paths)
#
env.bash
setup.bash
setup.sh
...
install/ --INSTALL SPACE 安装空间[-DCMAKE_INSTALL_PREFIX=/any/directorycmake默认是/usr/local](this is where installed targets for test installations go, not necessarily within workspace)
bin/
etc/
include/
lib/
share/
.catkin --Marking the folder as an install space (the file is emtpy)
env.bash
setup.bash -- Environment setup file for Bash shell
setup.sh -- Environment setup file for Bourne shell
... / 系统安装空间         /opt/ros/ROSDISTRO
opt/
ros/
groovy/
setup.bash -- Environment setup file for Bash shell
setup.sh -- Environment setup file for Bourne shell
setup.zsh -- Environment setup file for zshell
... 结果空间    source RESULT-SPACE/setup.sh     类似扫描安装空间与开发空间,替换系统通用下的对应文件.

总结:

src/                   --SOURCE SPACE  源空间
build/ --BUILD SPACE 编译空间
devel/ --DEVEL SPACE 开发空间
install/ --INSTALL SPACE 安装空间
ROS系统安装空间         /opt/ros/indigo

3)Overlays

catkin支持包的逐层覆盖, 当前最高,其它依据source的顺序逐层变高, 高层可覆盖低层.

    Example : Overlaying workspace  on top of local workspace2 install space on top of workspace1 devel space on top of system install  

    cd ~/workspace2/build
cmake -DCMAKE_INSTALL_PREFIX=~/ws2_installed ../src
make
make install source ~/ws2_installed/setup.bash cd ~/workspace3/build
cmake ../src
make

ros 环境变量设置 可以参考.bashrc文件

 #  slam_ws
source /opt/ros/indigo/setup.bash
source /home/yhzhao/slam_ws/devel/setup.bash export ROS_PACKAGE_PATH=~/slam_ws/src:$ROS_PACKAGE_PATH
export ROS_WORKSPACE=~/slam_ws/src

4)  catkin_make编译指定的包

$ catkin_make -DCATKIN_WHITELIST_PACKAGES="package1;package2"

恢复编译所有的包

$ catkin_make -DCATKIN_WHITELIST_PACKAGES=""

3. 对这句命令进行解释:

catkin build rovio --cmake-args -DCMAKE_BUILD_TYPE=Release -DMAKE_SCENE=ON

catkin build – Build Packages,编译rovio包

如果工作空间未初始化,可以自动完成工作空间初始化 (source ~/catkin_ws/devel/setup.bash)
It is used to build one or more packages in a catkin workspace. If a workspace is not yet initialized(初始化), build can initialize it with the default configuration(默认配置), but only if it is called from the workspace root. Specific workspaces can also be built from arbitrary working directories with the --workspace option.

--cmake-args    #cmake参数
-DCMAKE_BUILD_TYPE=Release

使用 CMake我们可以生成 debug 版和 release 版的程序。debug 版的项目生成的可执行文件需要有调试信息并且不需要进行优化,而 release 版的不需要调试信息但需要优化。这些特性在 gcc/g++ 中是通过编译时的参数来决定的,如果将优化程度调到最高需要设置参数-O3,最低是 -O0 即不做优化;添加调试信息的参数是 -g -ggdb ,如果不添加这个参数,调试信息就不会被包含在生成的二进制文件中。

CMake 中有一个变量 CMAKE_BUILD_TYPE ,可以的取值是 Debug、 Release、 RelWithDebInfo 和 MinSizeRel。当这个变量值为 Debug 的时候,CMake 会使用变量 CMAKE_CXX_FLAGS_DEBUG 和 CMAKE_C_FLAGS_DEBUG 中的字符串作为编译选项生成 Makefile ,当这个变量值为 Release 的时候,工程会使用变量 CMAKE_CXX_FLAGS_RELEASE 和 CMAKE_C_FLAGS_RELEASE 选项生成 Makefile。

现假设项目中只有一个文件 main.cpp ,下面是一个可以选择生成 debug 版和 release 版的程序的 CMakeList.txt :

 PROJECT(main)
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
SET(CMAKE_SOURCE_DIR .)
SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb")
SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")
AUX_SOURCE_DIRECTORY(. DIR_SRCS)
ADD_EXECUTABLE(main ${DIR_SRCS})

catkin_make 与cmake的更多相关文章

  1. make cmake catkin_make

    在Linux下进行C语言编程,必然要采用GNU GCC来编译C源代码生成可执行程序. 一.GCC快速入门 Gcc指令的一般格式为:Gcc [选项] 要编译的文件 [选项] [目标文件] 其中,目标文件 ...

  2. ROS编译:catkin简析

    博客转载自:https://blog.csdn.net/zyh821351004/article/details/50388429 Catkin tutorials: http://wiki.ros. ...

  3. eclipse+cmake+c++11+ros

    eclipse+cmake: https://www.vtk.org/Wiki/CMake:Eclipse_UNIX_Tutorial eclipse+c++11: https://wiki.ecli ...

  4. 删除某个ros包之后catkin_make冒错

    CMake Error at /home/ubuntu/Workspaces/rosProject/workspace1/devel/share/costmap_2d/cmake/costmap_2d ...

  5. CMake error:System Error:No such file or directory CMake error:Could not open file for write in copy operation xxxx.ros_Config.cmake.tmp.

    微型电脑或嵌入式与电脑还是有点不同的,在微型电脑上ros indigo 版本下利用catkin编译如果你遇到如下错误: CMake error:System Error:No such file or ...

  6. ros结合catkin_make和qtcreator

    首先是ros官网关于IDE的教程: http://wiki.ros.org/IDEs#QtCreator 1.qtcreator安装 从官网上下载.run文件, https://info.qt.io/ ...

  7. ROS catkin_make error Could not find a package configuration file provided by "actionlib_msgs"

    在使用ROS catkin_make编译的时候,出现类似如下错误 CMake Error at /opt/ros/kinetic/share/catkin/cmake/catkinConfig.cma ...

  8. Learning ROS: Ubuntu16.04下kinetic开发环境安装和初体验 Install + Configure + Navigating(look around) + Creating a Package(catkin_create_pkg) + Building a Package(catkin_make) + Understanding Nodes

    本文主要部分来源于ROS官网的Tutorials. Ubuntu install of ROS Kinetic # Setup your sources.list sudo sh -c 'echo & ...

  9. 使用cmake自动构建工程

    公司引擎是用cmake根据目标平台来构建工程的,刚接触的时候深深体会到cmake的方便:如果目标平台是windows,它可以帮你自动构建出vs工程:如果是安卓,自动构建出eclipse工程,如果是IO ...

随机推荐

  1. Asynchronous programming with Tornado

    Asynchronous programming can be tricky for beginners, therefore I think it’s useful to iron some bas ...

  2. CSS3 圆角属性 border-radius和-webkit-border-radius使用

    CSS3 圆角属性 border-radius 在 CSS3 中新增了一个 border-radius 边框半径属性,即大家常用的圆角效果.这使得制作圆角将不再麻烦,只需对所用对象加一个 border ...

  3. MS SQL Server 定时任务实现自动备份

    SQL Server Express 版本是没有SQL 代理服务的,从而导致不能使用SQL Server的定时自动备份功能.真心感觉这就是一个坑,虽然Express是学习的版本,但是精简的也太多了.另 ...

  4. IntelliJ IDEA创建maven web项目(IDEA新手适用)

      步骤一:首先先创建一个project,在这里就是创建一个maven的工作空间 步骤二:按照下面的步骤操作就可以了,最后next 首先,选择左边的maven 然后在右边Creater from ar ...

  5. c++官方文档-模版函数和重载

    #include<stdio.h> #include<iostream> #include<queue> #include<map> #include& ...

  6. CentOS Apache配置详解

    要想在linux上实现网页服务器(www)需要Apache这个服务器软件,不过Apache仅能提供最基本的静态网站数据而已,想要实现动态网站的话,最好还是要PHP与MySQL的支持,所以下面我们将会以 ...

  7. 0_Simple__template

    简单的 CUDA 应用模板,白送的 Sample. ▶ 源代码 //template_cpu.cpp extern "C" void computeGold(float *, co ...

  8. HTML5 Canvas ( 文字横纵对齐 ) textAlign, textBaseLine

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. FireFox 书签 缓存 路径设置

    English ver down https://www.mozilla.org/en-US/firefox/new/ add ons https://addons.mozilla.org/en-US ...

  10. xe DateTimePicker.Date bug

    xe6 bug xe7 ok DateTimePicker1->DateTime.DateString(); DateTimePicker1->DateTime.DateTimeStrin ...