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.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" %fInstall the Python support plugin to be able to code in both C++ and Python from the single IDE.
- 504
- 1
- 3
- 17
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.bashfile. - Go to the
srcdirectory of your workspace. - Start CLion from the console from your
srcdirectory. - 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 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.
- 311
- 1
- 3
- 8
-
Could you include how to run programs with launch files and debugging support with clion as well? – Eric Jul 19 '17 at 17:58
-
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. – Jarno Jul 24 '17 at 20:18
New and Simplest Approach:
Install
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.
- 242
- 2
- 12
Setup CLion with ROS
is a nice description on ROS Answers.
https://answers.ros.org/question/284786/setup-clion-with-ros/
- 111
- 2
-
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. – Mark Booth Nov 15 '18 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?
- 1
~/.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. – Stefan Fabian Dec 17 '17 at 20:53