Skip to content

Working With Eclipse CDT

Nadav Har'El edited this page Feb 21, 2017 · 10 revisions

Install Eclipse

Install Eclipse, and its CDT (C Development Tooling), as is recommended on your distribution. E.g., on Fedora, "dnf install eclipse-cdt" is enough. If you prefer to install from source, check out the instructions in https://www.eclipse.org/cdt/.

Increase heap size

Eclipse uses a Java virtual machine started with a fixed upper limit on its heap size, defined in /etc/eclipse.ini. The default limit is sometimes not large enough for indexing the OSv project. It's recommended to edit /etc/eclipse.ini (as root) and make sure the "-Xmx" setting is at least 1 GB.

Download OSv

Download OSv from git, and run "make". It is important to run "make" once before editing, because the first time we build OSv generates some header files which are needed for Eclipse to proper parsing of the other source files.

Creating OSv Project

Under File -> New -> Project, select C/C++ folder and than select "Makefile Project with Existing Code".

Click Next.

Give a project name and select the place where OSv code was downloaded.

You can now click Finish.

Configuring OSv project.

OSv has some particularities that eclipse do not understand as default, such as:

  • It does have it's own libc/stdc++/libboost implementation
  • Its' a Kernel
  • It's c++11
  • It has a lot of includes paths that preprocessor should be awere of.

Unfortunately there is no magic configuration file that address all of this, so some manual configuration is needed.

Configure include paths and defines to OSv

Project -> Properties -> C/C++ General -> Preprocessor Includes -> GNU C++ -> CDT User Setting Entries -> Add a "Preprocessor Macro"; Name: __GXX_EXPERIMENTAL_CXX0X__ value: 1

Project -> Properties -> C/C++ General -> Preprocessor Includes -> GNU C++ -> CDT User Setting Entries -> Add a “Include Directory”, in “Filesystem”, “/usr/include”

Configure g++ special arguments

To use OSv provided libs and includes, and to work correctly with c++11, we need some more tweaks. So go to:

Project -> Properties -> C/C++ General -> Preprocessor Includes

Under Provides tab, select CDT GCC Built-in Compiler Settings and uncheck "Use global provider shared between projects". Use the following command:

${COMMAND} -E -P -v -dD "${INPUTS}" -std=c++11 -include /YOUR_PATH_TO_OSV_SOURCE/include/api/stdalign.h -nostdlib -nostdinc -nostdinc++

do not forget to replace YOUR_PATH_TO_OSV_SOURCE

Configure eclipse indexer

This will prevent indexer to guess things in a wrong way:

Project -> Properties -> C/C++ General -> Indexer

Uncheck: "Index source files not included in the build" and "Allow heuristic resolution of includes'.

Configure coding style

To make OSv's code formatter conform to OSv's coding style, go to Project -> Properties -> C/C++ General -> Formatter, Set "Enable project specific settings", choose the K&R formatter and then click on the "Edit..." button to edit the formatter, choose a new name (e.g., "OSV") and in the "Indentation" setting choose "spaces only" as a tab policy.

Clone this wiki locally