Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

Catkin Eclipse

HannesSommer edited this page Feb 20, 2015 · 26 revisions

Integrating a catkin package in Eclipse

This guide explains how to set up an Eclipse project for a single catkin package when using the catkin command line tools.

Preliminary setup (global settings in eclipse)

We first need to tweak Eclipse to recognize includes from the compilation commands and to properly recognize C++11 traits (if we are using C++11): Go to Window->Preferences->C/C++->Build->Settings and select the "Discovery" tab. In "CDT GCC Build Output Parser [ Shared ]" prepend ".*" to the regular expressions, e.g.:

(.*gcc)|(.*[gc]\+\+)|(.*clang)

This will help Eclipse CDT recognize compiler calls that also contain the path to the compiler. On same page check "Project" for "Container to keep discovered entries". Then, in "CDT GCC Built-in Compiler Settings [ Shared ]" add the "-std=c++11" flag to obtain e.g.:

${COMMAND} -E -P -v -dD -std=c++11 "${INPUTS}"

Compilation scripts

In order to generally compile (especially after changes to CMakeLists or when running tests), we need to source the ROS setup script. In order for eclipse to do that when building, the simplest way is to call custom scripts. Create a file "/usr/local/bin/eclipsemake" with the following contents:

#!/bin/bash

source /opt/ros/indigo/setup.bash
make "$@" VERBOSE=1 -j8

In the same folder, create "eclipsemake-tests" with run_tests appended to the make command, so it looks like this:

#!/bin/bash

source /opt/ros/indigo/setup.bash
make "$@" VERBOSE=1 -j8 run_tests

If you're running Eclipse on a virtual machine you may want to replace '-j8' with '-j1' to save memory. To make both files executable, run sudo chmod +x /usr/local/bin/eclipsemake*

Adding a catkin package as project to eclipse

Reminder: This guide is tailored to the catkin command line tools, which keep separate build directories for each package. Also, "package" does not include meta-packages (packages containing other packages and no source files of their own).

File->New->Project... , C/C++->"Makefile Project with Existing Code" , "Next", enter a name and browse to your package location in "Existing Code Location", hit Finish

Right-click the project and go to Properties->"C/C++ Build". In the "Builder Settings" Tab, set the custom build command to eclipsemake and change the "Build directory" to the folder corresponding to your package in the catkin build folder (typically /home/<username>/catkin_ws/build/\<project name\>). "Apply". (Note: Make sure not to use ~ instead of /home/<username>)

In "C/C++ Build"->Environment add a variable VERBOSE with value 1, add to all configurations. "Apply"

In "C/C++ General"->"Paths and Symbols", tab "Symbols", add __GXX_EXPERIMENTAL_CXX0X__ in "GNU C++" with no value, "Apply".

Go to "C/C++ General"->"Preprocessor Includes", "Providers" tab. Check "CDT GCC Build Output Parser" and "CDT GCC Built-in Compiler Settings" and verify that you "Use global provider shared between projects" in both. "Apply" and "OK".

The next step is now to completely rebuild your project, so that eclipse can parse include directories from build commands. Right-click your project and select "Clean Project". Then right click again and "Build Project" or hit Ctrl+B. Rebuilding the entire project is not necessary if you can put up with missing include resolves for a while - the more files you compile, though, the more they will go away. Note that you could still have missing include resolves in your test files until you also compile those from within eclipse - see below.

At this point you should probably make sure that git ignores the eclipse configuration files. In your package, append to .gitignore (create if nonexistent):

.cproject
.project
.settings

Do it automatically based on project file templates : eclipsify

The project https://github.com/ethz-asl/eclipsify/ tries to get rid of the manual work by providing templates for project configuration files and instantiate them for your catkin projects.

Features:

  • Create eclipse CDT project configuration files based on some understanding of the catkin workspace layout
  • Adding the new project to your workspace configuration.
  • User provided (partial) templates

It is not yet fully mature. For current limitations see https://github.com/ethz-asl/eclipsify/issues.

Copy settings from one project to another (fresh one)

You can use the experimental https://github.com/ethz-asl/programming_guidelines/blob/master/eclipse-tools/eclipseProjectMigrator to copy eclipse project settings (stored in the files above) among projects of a common catkin workspace (!). To copy from project A to project B (possibly creating B) to save the manual project setup above for B just use :

eclipseProjectMigrator <A_PATH> <B_PATH>

preferably from within you CATKIN_WORKSPACE/src folder.

Warning: it is using a very simple approach (basically copying files while replacing names and paths) and is not much tested.

Running tests from within eclipse

In your project properties, go to "C/C++ Build" and click "Manage Configurations". Add a configuration "Tests" that copies the settings from default. Switch to that configuration and under "Builder Settings" set your custom build command to "eclipsemake-tests". "Apply" and "OK".

You can now launch the unit tests by selecting "Tests" in the drop-down menu next to the hammer-shaped icon in the eclipse toolbar.