Ask Your Question
3

Guide for ROS2/colcon project in CLion

asked 2020-03-25 18:18:11 -0500

Ciel gravatar image

updated 2020-03-26 14:38:38 -0500

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/...

edit retag flag offensive close merge delete

Comments

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...).

Dirk Thomas gravatar image Dirk Thomas  ( 2020-03-26 14:46:37 -0500 )edit

I have never used CLion before. Maybe this (https://www.jetbrains.com/help/clion/...) approach can be helpful. There is a PR to colcon-cmaketo generate a workspace-level compilation database, see https://github.com/colcon/colcon-cmak....

Dirk Thomas gravatar image Dirk Thomas  ( 2020-03-26 14:48:26 -0500 )edit
1

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...

_andrei_ gravatar image _andrei_  ( 2021-01-26 04:21:58 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2021-08-09 09:06:57 -0500

updated 2021-08-12 04:41:25 -0500

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.
edit flag offensive delete link more
1

answered 2020-10-23 11:19:31 -0500

calvertdw gravatar image

updated 2020-10-23 11:21:25 -0500

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

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
edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

4 followers

Stats

Asked: 2020-03-25 18:18:11 -0500

Seen: 1,583 times

Last updated: Aug 12