0
$\begingroup$

Rosanswers logo

Is there a guide for using CLion IDE to build/debug ROS2 with colcon on a mixed python/CPP project? CLion was awesome for this with ROS1 projects, for source level debugging with variable watch/modify and using IntelliJ for project navigation and refactoring. I want to get away from any ROS1/catkin/ament stuff and I do not understand the colcon/CMake/make toolchain or the CLion configuration enough to tackle it.

An example using the standard ROS tutorials/example projects would be terrific since I already know that I can build those using colcon build.

One plausible workaround would be to have colcon build generate a top level CMakeLists.txt file? If that is indeed possible then CLion may be able to open the project that way (that worked for ROS1)

Eventually I would like to be able to use Docker environments to assist with collaborative development but I am not interested in that extra layer just yet.

ENV Info: Ubuntu 18.04.3 x64 Kernel 5.3.0-40-generic CLion 19.3.4 ROS2 Eloquent

I also have a similar support request open at JetBrains: https://youtrack.jetbrains.com/issue/CPP-19558


Originally posted by Ciel on ROS Answers with karma: 51 on 2020-03-25

Post score: 5


Original comments

Comment by Dirk Thomas on 2020-03-26:
catkin_make_isolated / catkin_tools / colcon / ROS 2 conceptionally all don't support a workspace-level CMake file since that approach doesn't work on a larger scale (see http://design.ros2.org/articles/ament.html#building-within-a-single-cmake-context).

Comment by Dirk Thomas on 2020-03-26:
I have never used CLion before. Maybe this (https://www.jetbrains.com/help/clion/compilation-database.html) approach can be helpful. There is a PR to colcon-cmake to generate a workspace-level compilation database, see https://github.com/colcon/colcon-cmake/pull/69.

Comment by andrei on 2021-01-26:
Thank you both for the links. I tried to use Compilation Database in CLion, but it can be used now only to check compilation errors. It can't build and can't show cmake issues.

Also I tried previous approach with single cmake, indeed, it is not supported at all. I gave up when trying to depend on custom messages from the same workspace.

People suggest to use VCode for ROS2, but it's the last thing I want to try...

$\endgroup$

2 Answers 2

1
$\begingroup$

Rosanswers logo

CLion IDE can be conveniently used with ros2. It happens thanks to CLion support of Compilation Database (CD) and colcon creating a top-level CD file for the entire workspace. Here is how to set it up:

  1. Build your ros2 project workspace with CMAKE_EXPORT_COMPILE_COMMANDS, e.g. colcon build --cmake-args -DCMAKE_EXPORT_COMPILE_COMMANDS=1.
  2. This creates a compile_commands.json file in your build/ directory. You need to copy it to top-level directory of your workspace (where you have src/ and build/ directories. You can automate this step.
  3. Run your CLion, click File->Open, and select the compile_commands.json file, open it as a project.
  4. Things should work now. To check, hold Ctrl over an object of a class from another workspace package or from your ros2 distro package. You should be able to navigate to definitions with Ctrl-click.

Originally posted by Adam Dabrowski with karma: 116 on 2021-08-09

This answer was ACCEPTED on the original site

Post score: 10


Original comments

Comment by Minphie on 2021-11-30:
Then answer is very helpful but then how can I debug a ros2 node in clion?

Comment by magladko on 2023-01-17:
For the new visitors, there is a tutorial by JetBrains: ROS2 with Clion tutorial I prepared some basic Github repo for Ubuntu users, so You can take a look (it's very basic): repo

$\endgroup$
0
$\begingroup$

Rosanswers logo

There is a CMakeLists.txt file here that you can use to import into CLion: https://gist.github.com/rotu/1eac858b808b82bbf1b475f515e91636

Place this CMakeLists.txt file in your ros2_ws root.

To import all the projects in your workspace, comment out the --packages-select line at the end.

For large workspaces such as a full ROS 2 build, it is recommended to just select a few to build with the --packages-select option.

Steps to import are:

  1. colcon build
  2. source install/setup.bash
  3. Launch clion from that terminal
  4. Open the CMakeLists.txt in the workspace root

Originally posted by calvertdw with karma: 25 on 2020-10-23

This answer was NOT ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.