CLion for catkin projects

Why use CLion?


  • Better indexing and intelligence hints for C++ than Eclipse and QtCreator-desktop.
  • Free for students.
  • Also integrate PyCharm already.
  • Good Git integration (although I am still used to commandline git).
  • I really like the code inspection clang-tidy function which makes the code style more modern.

Initial set-up


Highly recommend you to add source <CATKIN_WORKSPACE_DIR>/devel/setup.bash to the end of ~/.bashrc or ~/.zshrc (Depends you use bash or zsh). So when you type

echo $ROS_PACKAGE_PATH

you can find both <CATKIN_WORKSPACE_DIR>/src and /opt/ros/<ROS_DIST>/share. So next time you open any terminal, your cmakelist can find the package of catkin.

Method 1: Launch CLion via terminal

sh <CLION_INSTALL_DIR>/bin/clion.sh

Recommend you to make alias for this command in ~/.bashrc.

Method 2: Launch CLion via app icon on sidebar

Just edit /usr/share/applications/jetbrains-clion.desktop. If it does not exist, open up Clion and hit Tools > Create Desktop Entry first. Here I give an example and if you are using zsh, just change bash to zsh.

[Desktop Entry]
Version=1.0
Type=Application
Name=CLion
Icon=XXX/clion-2017.2.3/bin/clion.svg
Exec=bash -i -c "XXX/clion-2017.2.3/bin/clion.sh" %f
Comment=The Drive to Develop
Categories=Development;IDE;
Terminal=false
StartupWMClass=jetbrains-clion

Settings

In CLion, you can set the Toolchain dialog (including CMake, C++ compiler, gdb) so it can be consistent with your current system-level toolchain.

Also you can set the pass any envrionment variables and parameters to CMake in CLion by using the CMake dialog.

tool chain settingCmake setting
C++ tool chain settingsCmake settings

CLion builds your project in cmake-build-debug by default. If you want to change that, you could easily set:

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "my_dir")

Or change the build output directory in the CMake dialog as well.

In addition, the Run/Debug Configurations dialog in the right up corner allows you to set program execution arguments, working directory, and environment variables.

open debug & run settingmodify execution argument
open debug & run settingmodify execution arguments

Now try to build & run your ROS project! I hope this could provide you with better experience on project development.