Skip to content

Eclipse

Andreas Pfrunder edited this page May 2, 2017 · 4 revisions

Create Desktop Entry for Eclipse

First of all install the Eclipse IDE from their website into the /opt folder. Now we create a Desktop entry which lets you startup Eclipse from the launcher panel within the ROS environment:

  1. Create the following file and enter:
sudo gedit /usr/share/applications/eclipse.desktop
  1. Adapt the followig code to reflect your system:
[Desktop Entry]
Name=Eclipse
Type=Application
Exec=bash -i -c "source /opt/ros/kinetic/setup.bash && source /home/USERNAME/CATKIN_WS/devel/setup.bash && /opt/eclipse/eclipse" 
Terminal=false 
Icon=/opt/eclipse/icon.xpm
Comment=Integrated Development Environment 
NoDisplay=false 
Categories=Development;IDE 
Name[en]=eclipse.desktop

where you should adapt USERNAME and CATKIN_WS to yourself.

Build packages such that Eclipse can import them properly

  1. Go into your catkin workspace and build everything using the following command:
catkin build  --force-cmake -G"Eclipse CDT4 - Unix Makefiles"

Optionally you can additionally use the -DCMAKE_BUILD_TYPE=Debug argument in case code should be compiled for debugging. 2. Run the following script from the root of your workspace to create the required .project files:

ROOT=$PWD
cd build
for PROJECT in `find $PWD -name .project`; do
    DIR=`dirname $PROJECT`
    echo $DIR
    cd $DIR
    awk -f $(rospack find mk)/eclipse.awk .project > .project_with_env && mv .project_with_env .project
done
cd $ROOT

Some preliminary settings for Eclipse

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)

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}"

Adding the project to Eclipse

File → New → Project... → C/C++ -> Makefile Project with Existing Code Now choose a name and give the location of the catkin_ws/src folder, choose LinuxGCC and finish.

Some build setup

  1. Right click on the project you just created and go to "Properties" -> "C/C++ Build" -> "Environment" and add a variable VERBOSE with value 1, add to all configurations and apply.
  2. In "C/C++ General"->"Paths and Symbols", tab "Symbols", add __GXX_EXPERIMENTAL_CXX0X__ in "GNU C++" with no value and apply.
  3. 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. Then press apply and ok.

Set additional indexer settings

  1. Right click on the project and go to "Properties" -> "C++-General" -> "Paths and Symbols"
  2. In the "Includes" tab select "GNU C++" under "Languages" click "Add" and add:
/usr/include/c++/5
/usr/include/x86_64-linux-gnu/c++/5
[PATH_TO_CATKIN_WS]/devel/include
  1. In the "Libraries" tab make sure you have an entry "stdc++".
  2. In the "Library Paths" tab click "Add" and add:
/usr/lib/gcc/x86_64-linux-gnu/5
  1. Go to "C/C++ General" -> "Indexer", and click on "Enable project specific settings" and "Allow heuristic resolution of includes".
  2. Next go to Window -> Preferences -> C/C++ -> Build -> Settings -> Discovery -> CDT GCC Built-In Compiler Settings, add "-std=c++11" to the command line, i.e. it should say
${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}" -std=c++11
  1. Now rebuild the index by right clicking on the project and under "Index" select "Rebuild".

Add build option for single package

  1. Right click on your Project -> Properties -> C/C++ Build tab → Manage Configuration → New
  2. Name your build configuration. In the Builder Settings tab
  3. Build command: catkin build PACKAGE_NAME --force-color --no-status -v -j8
  4. Build directory: /home/USERNAME/CATKIN_WS/build
  5. In the Behavior tab edit: Build (incremental build) "" and Clean --make-args clean

Eclipsify

Another option is to use Eclipsify and import every package separate. This has the advantage that most of the settings are already done. However, in order to get good linkage between the different files, lots of packages need to be imported which can be very annoying for large projects.

  1. Go to the root of your catkin workspace and type:
eclipsify -s -W devel/ CATKIN_PACKAGE
  1. File -> Import -> Existing Projects into Workspace -> Select the root directory: Browse... -> Choose your catkin_ws/src. Then "Deselect All" and then only select the package you want and Finish.
  2. Then right click on the freshly added package and go to Properties → C/C++ General → Preprocessor Include Paths, Macros etc. -> Providers -> CDT GCC Build Output Parser -> check "Use global provier shared between projects"
  3. Clean project by right clicking on it -> "Clean Project" and then build it "Build Project".