ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

catkin: When are the install directives in CMakeLists.txt effective?

asked 2021-10-25 00:08:38 -0500

akihiko gravatar image

updated 2021-10-26 09:08:01 -0500

lucasw gravatar image

I tested a simple catkin package, and have some questions about the install directives in CMakeLists.txt.

My environment is:

  • OS: Ubuntu 18.04
  • ROS: melodic
  • catkin system: python-catkin-tools

The package consists of:


  • CMakeLists.txt
  • package.xml
  • scripts/
  • src/
    • test1_node.cpp

So, there are two noes in the package (one is made with C++ and the other is a Python script).

The first version of CMakeLists.txt is:

cmake_minimum_required(VERSION 3.0.2)
find_package(catkin REQUIRED


add_executable(${PROJECT_NAME}_test1_node src/test1_node.cpp)
set_target_properties(${PROJECT_NAME}_test1_node PROPERTIES OUTPUT_NAME test1_node PREFIX "")
add_dependencies(${PROJECT_NAME}_test1_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

After executing $ catkin build --this, the following (executable-related) files were produced:

  • ./devel/lib/test_hoge1/test1_node (symbolic link to the below file)
  • ./devel/.private/test_hoge1/lib/test_hoge1/test1_node

Running nodes by rosrun,

$ rosrun test_hoge1 test1_node
#--> ./devel/lib/test_hoge1/test1_node is executed.
$ rosrun test_hoge1
#--> ./src/test_hoge1/scripts/ is executed.

Then I added the following directives into CMakeLists.txt:

install(TARGETS ${PROJECT_NAME}_test1_node

catkin build --this produced the following:

  • ./build/test_hoge1/catkin_generated/installspace/
  • ./devel/lib/test_hoge1/test1_node (symbolic link to the below file)
  • ./devel/.private/test_hoge1/lib/test_hoge1/test1_node is a copy (not a symbolic link) of the script in src/scripts/, so it is a snapshot at building the package.

However executing the script by $ rosrun test_hoge1 still uses ./src/test_hoge1/scripts/

Based on those experiments, my questions are:

  • The install directive (for C++ nodes) in CMakeLists.txt looks doing nothing. When is it effective? Or, if we work only with Ubuntu, is it unnecessary?
  • Although the catkin_install_python directive copies the scripts as their snapshots, rosrun executes the original scripts. This behavior is confusing. Did I make some mistakes in CMakeLists.txt, or is it a designed behavior? If it is the normal behavior, When and why do we need to use catkin_install_python? If we work only with Ubuntu, is it unnecessary?
edit retag flag offensive close merge delete


Note that this is essentially a duplicate of #q331276. There are probably others.

gvdhoorn gravatar image gvdhoorn  ( 2021-10-25 02:37:46 -0500 )edit

@gvdhoorn Partially. I'm also asking the necessity of installation, if the package works without doing that.

akihiko gravatar image akihiko  ( 2021-10-25 02:51:05 -0500 )edit

As you should know by now, asking multiple questions in a single post goes against best-practice for a Q&A site like ROS Answers.

gvdhoorn gravatar image gvdhoorn  ( 2021-10-25 03:35:12 -0500 )edit

1 Answer

Sort by » oldest newest most voted

answered 2021-10-25 01:53:36 -0500

gvdhoorn gravatar image

updated 2021-10-25 03:38:29 -0500

When are the install directives in CMakeLists.txt effective?

Seeing as you are using catkin_tools, I believe this can all be explained by quoting the relevant documentation (this section specifically):

Without any additional arguments, packages are not “installed” using the standard CMake install() targets. Addition of the --install option will configure a workspace so that it creates an install space and write the products of all install targets to that FHS tree. The contents of the install space, which, by default, is located in a directory named install will look like the following:

$ ls ./install bin           etc            include
lib            setup.bash       setup.zsh      share

This is a sub section of the documentation of the config verb.

To configure your workspace such that catkin_tools will also create an install space, you'd run:

catkin config --install

after that, you'd need to:

catkin clean -y

and then a final:

catkin build

provided all your packages have correct build scripts, you should now see all install(..)-ed artefacts in the install space.

So to answer your question: packages will only be installed (to the install space) when your workspace has been configured for it.

edit flag offensive delete link more


Thanks for answering. Although this is explaining how to install the files (and where), it doesn't mention why the installation is necessary (what are the benefits, and what are the disadvantages if we do not do it). Could you add that to you answer, please?

akihiko gravatar image akihiko  ( 2021-10-25 02:51:12 -0500 )edit

Could you add that to you answer, please?

No, I won't.

As I wrote above, asking multiple questions in a single post goes against best-practice.

Why things should be installed is only tangentially related to when they get installed, which was the main question as evidenced by the title of your post.

gvdhoorn gravatar image gvdhoorn  ( 2021-10-25 03:36:20 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2021-10-25 00:08:38 -0500

Seen: 122 times

Last updated: Oct 25 '21