Note: The following solution works for catkin build
, but not for catkin_make
. If you are using catkin_make
, please visit:
https://stackoverflow.com/a/35143865/2422098
https://www.jetbrains.com/help/clion/2020.2/ros-setup-tutorial.html#set-build-paths
CLion configuration for catkin_tools
workspaces (catkin build
)
Please excuse me for digging up an old question, but I just came across this problem and found a solution for CLion and catkin_tools
(i.e., when building with catkin build
).
I tested the proposed solution on 20.04 with ROS Noetic and CLion 2020.2.4.
According to the docs, catkin_tools
uses an individual devel workspace path for each ROS package:
https://catkin-tools.readthedocs.io/en/latest/advanced/linked_develspace.html
The devel prefix path for a package:
-DCATKIN_DEVEL_PREFIX:PATH=/home/<user-name>/catkin_ws/devel/.private/<package-name>
The build directory for a package:
/home/<user-name>/catkin_ws/build/<package-name>
To open and edit a ROS package in CLion, please follow these steps:
- run
catkin build
in the workspace
- Source
/opt/ros/$ROS_DISTRO/setup.bash
and your workspace setup.bash
in the devel folder
- After that, start CLion from the command line, so that it inherits the environment variables
- In CLion's Open Project wizard, navigate to the ROS package, and select the
CMakeLists.txt
. When prompted, click Open as Project
- Open the Settings Window (usually Ctrl+Alt+S)
- Navigate to "Build, Execution, Deployment" > "CMake"
- Under "CMake options", specify the devel prefix as mentioned above, and under "Build directory", specifiy the build directory as mentioned above:

Explanation:
When configured in the aforementioned way, the generated CMake files and build files that catkin build
creates are reused by CLion.
By default, when not configuring it to reuse the build files, CLion would create its own cmake-build-debug/
generation directory. I experienced the following issues with this dedicated generation/build directory:
Problems when CLion is not configured as described in the above steps:
- The nodes/libraries are built twice (CLion,
catkin build
), which increase development time.
- Libraries are built twice, but the CLion build links with
~/catkin_ws/devel
.so-files and not the cmake-build-debug/
.so-files. This is confusing when working on a ROS package with at least one library, since building the library in CLion is a dead-end and the .so-output is never used.
- Since executables are built twice,
rosrun
has an ambiguity problem as it finds two executables for the specified node. An executable selection prompt appears each time rosrun
is used.