2.2.1. Eclipse Managed Build

To begin with, this can be the simplest way to build a new Project. (But it only works with GCC and other Eclipse supported toolchains.) [1]

CDT gives a GUI to:

With Eclipse managed build, Eclipse can automatically create a set of makefiles. These make files can be used with standard make utility. Thus, if the project is managed within Eclipse, developers not using Eclipse can still build the software. It is also useful for automated standalone builds.

Note

Older versions of CDT used to refer this as a Managed make project

2.2.1.1. Creating a sample project

  1. Click File → New → Project

  2. Select C Project

    ../../../_images/e-wiz-new-prj-sel-c.png
  3. Name the project as Hello World.

  4. Select project type as Hello World ANSI C Project

  5. Select Tool-chain as MinGW GCC

    Select an empty Hello world ANSI C Project
  6. Click Next button

  7. Input your details

    Input your details
  8. Click Next button

  9. Select Advanced settings

    Go to Advanced Settings
  10. Select Current builder as Gnu Make Builder

    Select GNU Make builder in advanced settings of Eclipse
  11. Click OK button

  12. Click Finish button

  13. If you get a message to switch perspective, Click Yes

    Accept the request to change the perspective.

    This happens if the previous perspective was not C/C++ perspective.

This is how the Project Explorer view would look like.

A sample view of the Project Explorer of Eclipse
  1. The name of the project HelloWorld
  2. Eclipse would list executables and libraries of the project here.
  3. Eclipse would list include directories and header files here.
  4. Eclipse generated folder. The name is derived from the build configuration.
  5. Eclipse generated Makefiles
  6. The actual source file.

To build the project, do either of:

  • Press Ctrl + B

  • Click Project → Build All

  • Press the Build Button

    The build button in Eclipse toolbar

2.2.1.2. Build Configuration

Build configurations are different ways of building a code. The most basic would be debug mode and retail mode. In debug mode, the generated objects and executables have debug symbols. For large projects, this can become further complicated. Including files for test code, excluding files for test code, etc.

Each configuration can have unique set of source files, includes, #defines, and other compiler/linker parameters.

2.2.1.3. Changing Build Settings

Eclipse gives control over how the project gets build.

2.2.1.3.1. Include / Exclude Files from Build

Use Right Click → Resource Configuration → Exclude From Build to add/remove a source file from a Build Configuration

Even finer control can be achieved through, Project → Properties → C/C++ General → Paths and Symbols → Source Location (See Including / Excluding files & directories from build)

../../../_images/c-prj-prop-source-location.png

Including / Excluding files & directories from build

2.2.1.3.2. Compiler Directives

Through Project → Properties → C/C++ General → Paths and Symbols → Includes we can Add include paths to build.

../../../_images/c-cpp-add-more-includes.png

Add include paths to build

Through Project → Properties → C/C++ General → Paths and Symbols → Symbols we can Add compiler defines to build.

../../../_images/c-cpp-add-more-defines.png

Add compiler defines to build

2.2.1.3.3. Change the Make Utility

To Change the default build utility, from make to something else, go to Project → Properties → C/C++ Build → Builder Settings

../../../_images/c-build-change-make-utility.png

Change the default build utility

To change Advanced build settings , e.g. using Parallel jobs for build (-j), or build on every save, go to Project → Properties → C/C++ Build → Behaviour

../../../_images/c-build-make-advanced-settings.png

Advanced build settings

2.2.1.3.4. Advanced toolchain specific settings

The toolchain can be selected form Project → Settings → C/C++ Build → Tool Chain Editor.

To Change general settings of the Tool-Chain, like, enable warnings (-Wall), don’t include standard system header files during compilation (-nostdinc), etc. go to Project → Settings → C/C++ Build → Settings → Tool Settings

../../../_images/c-cpp-prj-toolchain-settings.png

Change general settings of the Tool-Chain

We can also Change the build artifacts (dll/lib/exe). We can control if we want to build a DLL/Shared Object, static library, or an executable out of this project.

../../../_images/c-cpp-build-type-exe-lib-dll.png

Change the build artifacts (dll/lib/exe)

2.2.1.3.5. Pre-Build and Post-Build Steps

To Add pre-build and post-build steps, go to Project → Settings → C/C++ Build → Settings → Build Steps

../../../_images/c-cpp-build-steps.png

Add pre-build and post-build steps

[1]Cygwin GCC, Linux GCC, MacOSX GCC, MinGW GCC, Solaris GCC are supported by default. The proprietary distributions based on Eclipse would also support the toolchains of that distribution.