In this tutorial of Eclipse Indigo (or Kepler), we will install C and C++ on Windows 7 with some examples.
Not really, but nothing is impossible of course!
Because Windows needs another software to create and manipulate C and C++.
This software is 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:
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++ and 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.
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:
(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.
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.
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.
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.
Fill your personal information > Next > Finish.
Our project, MyFirstProject will be available.
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:
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:
Normally, the errors will disappear or type all paths one by one in the Include panel.
If you plan to play with C, select GNU C on the Languages panel and just add these ones:
If you need the last one add it too:
Click Apply > OK.
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:
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:
Good job! It was a bit complex, but you are a winner, and now the world is yours.