Difference between revisions of "How to Setup CLion for ROS"
Line 31: | Line 31: | ||
[[Category:How to Guides]] | [[Category:How to Guides]] | ||
+ | [[Category:Software]] |
Revision as of 17:31, 14 September 2018
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.
- Open jetbrains-clion.desktop. It is usually in ~/.local/share/applications/ or /usr/share/applications/.
- NOTE You will need super user permissions to edit this file!
- Replace the line which sets the Exec variable with Exec=bash -i -c "/home/USER/Applications/clion-2018.2.2/bin/clion.sh" %f
- 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.
- Open your catkin_ws in CLion (select the CMakeLists.txt file in catkin_ws/src)
- Go to "File" - "Settings" - "Build, Execution, Deployment" - "CMake"
- Set the generation Path to catkin_ws/build and apply
- 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.
- Go to "File" - "Settings" - "Editor" - "File Types"
- Search for XML in the recognized files list
- Click the plus button next to "Registered Patterns" to add a new pattern
- Set the pattern to *.launch and click "Ok"