How can I setup the C++ IDE CLion to display documentation and auto completion correctly when working with ROS?
5 Answers
- Start CLion from a commandline with your sourced ROS workspace (i.e. after calling
source devel/setup.bash
) - Open a project's CMakeLists.txt, and tell it to open it as a project rather than as a file.
- That's it, you've got your workspace integrated :)
Debugging:
- Debugging built files (nodes which you run through
rosrun
) is easy, you just normally run them in the IDE - Debugging launch files is more complicated, as they cannot be launched by the IDE. You can launch the launch file from command-line, then find the PID of the node you want to debug, and connect the IDE debugger to it ("Run -> Attach to local process"). Of course this is difficult to use for capturing initialization bugs.
- Debugging nodes that are shell scripts or scripts in unsupported languages is impossible.
There are several more steps you could do to deepen the integration:
- Set the CMake Generation path in "Build, ... -> CMake -> Generation Path" to your workspace's build directory, so that you can compile only once in the IDE and have the results available in console (otherwise, you'll have two different builds, one in IDE, and one in console). Unfortunately, until https://youtrack.jetbrains.com/issue/CPP-1887 is fixed, you cannot use any variables in the default generation path, so setting up the catkin layout requires some manual work.
- To automatically source ROS when launching CLion, you can add the sourcing to
~/.xsessionrc
. This might, however, have unexpected consequences. If you don't want to do that, use the following approach. - Create a desktop launcher that launches CLion from the system menu (Dash, launcher panel etc.) with correct environment (if you source ROS in your
.bashrc
): I edited the desktop file~/.local/share/applications/jetbrains-clion.desktop
to look like the following. You also have to make sure the file is not writable for your updater scripts/Jetbrains toolbox, otherwise they'll overwrite it with each update.
.
[Desktop Entry]
Version=1.0
Type=Application
Name=CLion
Icon=/home/peci1/bin/jetbrains/apps/CLion/.icon.svg
Exec=bash -i -c "/path/to/clion/bin/clion.sh" %f
Comment=A smart cross-platform IDE for C and C++
Categories=Development;IDE;
Terminal=false
StartupWMClass=jetbrains-clion
If you're using Jetbrains toolbox to install CLion (which you should IMO), the path to the binary changes with every update (until https://youtrack.jetbrains.com/issue/ALL-653 is resolved), but you can use this trick to always launch the latest installed version:
Exec=bash -i -c "$(ls -td /path/to/jetbrains/apps/CLion/ch-0/*/ | head -n1)/bin/clion.sh" %f
Install the Python support plugin to be able to code in both C++ and Python from the single IDE.
-
1$\begingroup$ Alternatively, with Jetbrains Toolbox on autostart the desktop file can be changed to start toolbox with bash and thus when opening projects or CLion through the Jetbrains Toolbox app, it will also have the environment set up. $\endgroup$ Commented Dec 15, 2017 at 18:39
-
$\begingroup$ @StefanFabian Great idea. Could you please post the path to the desktop file of the toolbox, that is launched on startup? I wasn't even aware that desktop files can be launched on startup :) $\endgroup$ Commented Dec 17, 2017 at 20:24
-
2$\begingroup$ Sure! The desktop file - if autostart is enabled in the toolbox settings - should be located at
~/.config/autostart/jetbrains-toolbox.desktop
. You simply have to change the lineExec={TOOLBOX-COMMAND}
toExec=/bin/bash -i -c "{TOOLBOX-COMMAND}"
. However, I think the toolbox app overwrites this change (perhaps every time it starts). So, I'd recommend making that file immutable usingsudo chattr +i jetbrains-toolbox.desktop
. $\endgroup$ Commented Dec 17, 2017 at 20:53
Integrating CLion with ROS is actually straight forward and works out of the box if one knows how to do it:
- With your console, go into your ROS workspace and source the respective
setup.bash
file. - Go to the
src
directory of your workspace. - Start CLion from the console from your
src
directory. - Close any open projects in CLion and select
Import Project from Sources
- Select ONLY the
src
directory in your workspace for the import. - If CLion complains about
CMakeList.txt
already existing simply clickOpen Project
- CLion will build symbols for several minutes, then you should be ready to go.
If it still doesn't work make sure that you delete all .idea
files from your workspace, that might have been created in previous attempts at using CLion with ROS.
-
$\begingroup$ Could you include how to run programs with launch files and debugging support with clion as well? $\endgroup$– EricCommented Jul 19, 2017 at 17:58
-
$\begingroup$ I'm using CLion really just for writing code. For the rest I use the ROS command line tools. I do not know whether you could configure CLion to work with ROS in this respects as well. $\endgroup$– JarnoCommented Jul 24, 2017 at 20:18
New and Simplest Approach:
Install
ROS-Robot Operating System
plugin on CLion:you have to open the Settings (from the File menu); then from the left panel select plugin in order to show the plugin panel in the right side and select the marketplace tab; then search for ROS-Robot Operating System plugin and install it.
Import your ros_workspace by the installed plugin in File menu:
In order to import an existing workspace, you have to use the menu Import ROS workspace, selecting the workspace folder. In this case, the plugin will search from the configured ROS versions and it will setup the project in order to resolve the ROS dependency.
Setup CLion with ROS
is a nice description on ROS Answers.
https://answers.ros.org/question/284786/setup-clion-with-ros/
-
$\begingroup$ Welcome to Robotics Max. Thanks for your answer but we prefer answers to be self contained where possible. Links tend to rot so answers which rely on a link can be rendered useless if the linked content disappears. If you add more context from the link, it is more likely that people will find your answer useful. $\endgroup$ Commented Nov 15, 2018 at 18:22
You can also run roslaunch files from directly within CLION as mentioned here: http://wiki.ros.org/IDEs#CLion however when I start my launch files in the IDE, I get the following error: roslaunch: error: no such option: --master-logger-level
Apparently the plugin starts the launch file via:
/opt/ros/kinetic/bin/roslaunch --master-logger-level=info FOLDERNAME/FILENAME
However I did not specify this parameter myself. Does anyone know why it is introduced?