CLion is a great C++ IDE. It also has the advantage of being cross platform and working on Linux. It has become my IDE of choice on that platform. In this post I'll be sharing a couple of tips to use more productively with ROS.

Sourcing the ROS environment

Unfortunately CLion does not natively understand ROS. This can however be solved quite easily, we just need to change the .desktop file used to launch it so that it sources the ROS workspace. You can find it in ~/.local/share/applications/jetbrains-clion.desktop. If the file does not exist you can generate it from CLion by clicking Create Desktop Entry in the Tools menu.

The launcher should look like this:

[Desktop Entry]
Version=1.0
Type=Application
Name=CLion
Icon=/home/YOUR-HOME-DIR/ ... /.icon.svg
Exec="/home/YOUR-HOME-DIR/ ... /bin/clion.sh" %f
Comment=A smart cross-platform IDE for C and C++
Categories=Development;IDE;
Terminal=false
StartupWMClass=jetbrains-clion

To let CLion know about ROS we need a way to pass it the environment variables that get set by ROS. If you source a ros setup.bash file in your .bashrc then we just need to run CLion through bash to make it work. In this case just modify the Exec= line adding bash -i -c to the beginning.:

Exec=bash -i -c "/home/YOUR-HOME-DIR/ ... /bin/clion.sh" %f

If you installed CLion using the jetbrains toolbox app the toolbox will overwrite the launcher at every boot. There are two workarounds to this:

  • make the launcher read-only with chattr +i ~/local/share/applications/jetbrains-clion.desktop
  • make a copy of the launcher with
opted for the second option. I made a copy of the launcher, changed the Exec line and changed the Name line to Name=CLion (ROS Kinetic)

If you don't source the ROS setup.bash file from your .bashrc you can still get this to work. We just need to sourced it manually as part of the Exec command. If your ROS workspace is in ~/development/ros_ws/ then change the Exec line to :

Exec=bash -i -c "source ~/development/ros_ws/devel/setup.bash; /home/YOUR-HOME-DIR/ ... /bin/clion.sh" %f

You might have to logout and login again before the changes take effect.

Registering .launch files as xml

To get good syntax highlighting and completion in .launch files you will need to Clion that these are actually xml files. You can do this by opening File > Settings and looking for File Types in the Editor menu. Simply add *.launch to the XML section.