C++ - Eclipse - Installation of C/C++ Development Tools (CDT) and Cygwin for Windows

In this tutorial of Eclipse, we will install C and C++ on Windows with some examples.

Easy?

Not really, but nothing is impossible of course!

Why?

Because Windows needs another software to create and manipulate C and C++.
This software is Cygwin.

1. Installing Cygwin

So let's download it on the official website: http://www.cygwin.com/

If you download all files available with Cygwin, prepare yourself to wait several hours.
Indeed, you will need at least 7GB of data.

We do not really need all that stuff.

So let's download only necessary files.
For the following installation, we will use:

  • C:\soft\cygwin for the Root Directory
  • C:\soft\cygwin\local-package-directory for the Local Package Directory

After downloading the executable file, run this setup.exe file and then:

Next > Install from Internet > Next > C:\soft\cygwin > Install For All Users > Next > C:\soft\cygwin\local-package-directory > Next > Direct Connection > Next > Choose a Download Site > Next.

A new window appears for selecting packages.

In the Search input, write gnu and click Default to transform it into Install.

Do the same for gcc, gdb, c++, g++, make and transform Default into Install.

Click then Next, all files will be downloaded and installed.

Wait until it will be done, it may take a very long time.

Once all is downloaded and installed, click Finish.

2. Setting the Path of your Environment variables

Now we have to set our Path of the Environment variables.

To easy find them, click the Windows symbol, then in the research input write environment.

In the window select Edit the system environment variables.

A new window appears, click Environment Variables....

In system variables, select Path and Edit....

Add at the end of the line:

;C:\soft\cygwin\bin

(The semicolon must be written only if there is not already one.)

Then click OK > OK > OK.

Restart your computer! See you in few minutes.

3. Creating a new C++ project with Eclipse

OK, now Windows knows where find all binaries from Cygwin to use with Eclipse and C/C++.

We will use, for this example, the Eclipse for C/C++ developers - CDT.
If you do not have it, download the Indigo Eclipse version on the official website: http://www.eclipse.org

Let's install all needed tools for Eclipse.
Open Eclipse then > Help > Install New Software...
In the Work with area, select Indigo - http ://download.eclipse.org/releases/indigo.

Of course, change Indigo with your Eclipse version, such as Kepler, Luna, Mars, Neon or Oxygen.

Click Enter, then wait a few minutes until you can select elements.
If nothing happens, update your Eclipse:

Help > Check for Updates...
Retry the Installation of New Software.

Then, collapse Programming Languages.
Select:

  • Autotools support for CDT (Incubation)
  • C/C++ Development Tools
  • CDT Visual C++ Support

If they are white instead of blue and yellow, you already installed them.

Click Next > Next > I accept the terms... > Finish > Restart Now.

Let's now create a first application for beginners.

Open Eclipse > File > New > C++ Project.
Write the project name (MyFirstProject), then in the Project type select Executable > Hello World C++ Project.
On the Toolchains area, select Cygwin GCC.
Click Next.
Fill your personal information > Next > Finish.

Our project, MyFirstProject will be available.

A. Adding include libraries to a C++ project

Right click this project and select > Properties > C/C++ General > Paths and Symbols > Includes > GNU C++.

Click Add and type these paths if they are not already written:

  • C:/soft/cygwin/lib/gcc/i686-pc-cygwin/4.5.3/include/c++
  • C:/soft/cygwin/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/i686-pc-cygwin
  • C:/soft/cygwin/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/backward
  • C:/soft/cygwin/lib/gcc/i686-pc-cygwin/4.5.3/include
  • C:/soft/cygwin/lib/gcc/i686-pc-cygwin/4.5.3/include-fixed
  • C:/soft/cygwin/usr/include

Click Apply > OK.

Of course you can export these settings for all others projects.

When you adding these paths, above the panel, there is an Export Settings button.

Click it and choose a directory and a name to save them.

It will export as a XML file and may look like this:

<?xml version="1.0" encoding="UTF-8"?>
<cdtprojectproperties>
<section name="org.eclipse.cdt.internal.ui.wizards.settingswizards.IncludePaths">
<language name="Assembly Source File">

</language>
<language name="C++ Source File">
<includepath>C:/soft/cygwin/lib/gcc/i686-pc-cygwin/4.5.3/include/c++</includepath>
<includepath>C:/soft/cygwin/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/i686-pc-cygwin</includepath>
<includepath>C:/soft/cygwin/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/backward</includepath>
<includepath>C:/soft/cygwin/lib/gcc/i686-pc-cygwin/4.5.3/include</includepath>
<includepath>C:/soft/cygwin/lib/gcc/i686-pc-cygwin/4.5.3/include-fixed</includepath>
<includepath>C:/soft/cygwin/usr/include</includepath>

</language>
<language name="C Source File">

</language>
<language name="Object File">

</language>
</section>
<section name="org.eclipse.cdt.internal.ui.wizards.settingswizards.Macros">
<language name="Assembly Source File">

</language>
<language name="C++ Source File">

</language>
<language name="C Source File">

</language>
<language name="Object File">

</language>
</section>
</cdtprojectproperties>

In another project, just import these settings to have the same include files.
In the Select Project area, choose your current project and click Browse to import the file.

There is sometimes some bugs.

Indeed, Eclipse doesn't understand that include files are correct, even if you can build and run your project.
So try to:

  • Launch the Debug
  • Run as an Application
  • Modify the code and relaunch the Debug or the Run as an Application

Normally, the errors will disappear or type all paths one by one in the Include panel.

B. Adding include libraries to a C project

If you plan to play with C, select GNU C on the Languages panel and just add these ones:

  • C:/soft/cygwin/lib/gcc/i686-pc-cygwin/4.5.3/include
  • C:/soft/cygwin/lib/gcc/i686-pc-cygwin/4.5.3/include-fixed
  • C:/soft/cygwin/usr/include

If you need the last one add it too:

  • C:/soft/cygwin/lib/include/w32api

Click Apply > OK.

C. Let's complete this tutorial

Come back to our project now.
Right click on the project name and select Build Project.

It will generate a Debug or a Release directory with several folders and files such as:

  • src/MyFirstProject.o
  • src/MyFirstProject.d
  • src/subdir.mk
  • MyFirstProject.exe
  • makefile
  • objects.mk
  • sources.mk

Now you can execute your project, right click on the project and select:

Run as > Local C/C++ Application.

And normally in the console, you will see:

!!!Hello World!!!

Conclusion

Good job! It was a bit complex, but you are a winner, and now the world is yours. cool

Comments

Comment: 

Thank you very much!

Comment: 

Thanks very much for the detailed steps...It worked fine after a bit of struggle.

Crygwin took about an hour to install. The weird thing was that Eclipse wasnt building the .exe and .o files initially and reporting some 'binary not found 'error. Finally I uninstalled Bitdefender antivirus which was blocking the build process!!

Kiran

Comment: 

Thanks so much, this is the best tutorial online!

Comment: 

Thank you very much. Wrestled with this all day and finally got it going due to this page :)

Comment: 

Thank you very much

Comment: 

Thanks a lot for this tutorial.
It is awesome.....!!!!

Comment: 

Thank You so very much ....You are a life saver!!!

Comment: 

Thanks a lot, great tutorial!

Comment: 

Thank you! It's really helpful article!

Comment: 

Thank you so MUCHHHHHH!

You just helped me setup my station after two days of struggling!

YES!

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.