How can I setup the C++ IDE CLion to display documentation and auto completion correctly when working with ROS?
- Start CLion from a commandline with your sourced ROS workspace (i.e. after calling
- 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 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.desktopto 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.
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
- Go to the
srcdirectory of your workspace.
- Start CLion from the console from your
- Close any open projects in CLion and select
Import Project from Sources
- Select ONLY the
srcdirectory in your workspace for the import.
- If CLion complains about
CMakeList.txtalready existing simply click
- 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.
New and Simplest Approach:
ROS-Robot Operating Systemplugin 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.
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?