Home Basic usage of ROS (3)
Post
Cancel

Basic usage of ROS (3)

How to Complete CMakeLists.txt and package.xml

In ROS developing, CMakelists.txt and package.xml are two important files to build a package. Only the files under your package direcotry need to be modified. Since you are not sure what dependencies you are going to use at the beginning, therefore in real developing process the CMakeLists.txt and package.xml writing can’t be done completely by catkin_create_pkg.

CMakeLists.txt

Here are several basic commands:

FunctionCommandUsage
Environment Configurationcmake_minimum_required(VERSION x.x.x)Set up the minimum version of CMake installed on your computer
Environment Configurationproject(xxx)Package name (automatiaclly generated by ROS)
Find dependenciesfind_package(XX REQUIRED xxx)Normally catkin is necessary
Add executable targetsadd_executable(EXEC FILES)EXEC-executable file name; FILES-all compilation units (.cpp)
Add target libraryadd_library(LIB FILES)LIB-library name; FILES-all compilation units (.cpp)
Link librariestarget_link_libraries(EXEC LIB)EXEC-executable file name;LIB-library name
Include header filestarget_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)CMAKE_CURRENT_SOURCE_DIR=PACKAGE/src

For complete tutorials, go to ROS wiki — CMakeLists.txt for further info.

Here we find that somewhere has # commented, somewhere has ## commented, somewhere has no comment. This a small trick:

  • No comment———This part is indispensible. You’d better not comment them or your project can’t be made.
  • # commented——This part is optional, you can uncomment them when you need.
  • ## commented—–This part is the real comment. Don’t uncomment them.

Package.xml

This post is licensed under CC BY 4.0 by the author.

Basic usage of ROS (2)

Usage of Ubuntu on PC installed Windows Before