Difference between revisions of "How to Setup CLion for ROS"

From RoboJackets Wiki
Jump to navigation Jump to search
m
 
(One intermediate revision by one other user not shown)
Line 30: Line 30:
 
# Set the pattern to <tt>*.launch</tt> and click "Ok"
 
# Set the pattern to <tt>*.launch</tt> and click "Ok"
  
[[Category:How to Guides]]
+
[[Category:How to Guides: Technical]]
 +
[[Category:Software]]

Latest revision as of 21:58, 5 February 2020

CLion is a popular C/C++ IDE from [JetBrains](http://www.jetbrains.com/). While it works natively with CMake projects, it cannot work out of the box with ROS projects. Catkin requires certain extensions over CMake.

I found [this StackOverflow guide](https://answers.ros.org/question/284786/setup-clion-with-ros/) very helpful. I'm copying its instructions here so that we can update them as necessary into the future.

Change CLion's .desktop file

If you follow the default ROS installation instructions, you add commands to your .bashrc file which enable catkin tools. Because CLion does not run in an interactive bash session by default, it cannot access the catkin tools. This step changes the way CLion is launched, so it can access the catkin tools.

  1. Open jetbrains-clion.desktop. It is usually in ~/.local/share/applications/ or /usr/share/applications/.
    1. NOTE You will need super user permissions to edit this file!
  2. Replace the line which sets the Exec variable with Exec=bash -i -c "/home/USER/Applications/clion-2018.2.2/bin/clion.sh" %f
  3. Save and close the file

Set the Build Directory

By default, CLion builds projects in cmake-build-debug or cmake-build-release based on the build type. ROS expects your catkin workspace to be built in catkin_ws/build, so we need to redirect CLion.

  1. Open your catkin_ws in CLion (select the CMakeLists.txt file in catkin_ws/src)
  2. Go to "File" - "Settings" - "Build, Execution, Deployment" - "CMake"
  3. Set the generation Path to catkin_ws/build and apply
  4. Reload the CMake project in CLion

Syntax Highlighting in Launch Files

CLion, like many IDEs or editors, offers syntax highlighting. CLion's highlighting chooses the language to use based on a list of file types in the IDE's settings. It doesn't know about launch files out of the box, so we need to add a rule for those.

  1. Go to "File" - "Settings" - "Editor" - "File Types"
  2. Search for XML in the recognized files list
  3. Click the plus button next to "Registered Patterns" to add a new pattern
  4. Set the pattern to *.launch and click "Ok"