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.
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++, 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:
;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.
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:
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.
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:
!!!Hello World!!!
Good job! It was a bit complex, but you are a winner, and now the world is yours.
Comments
Samer (not verified)
Thursday, November 10, 2011 - 2:46am
Permalink
Thank you very much!
Thank you very much!
Kiran Jose (not verified)
Wednesday, March 7, 2012 - 11:01pm
Permalink
Thanks very much for the
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
BG (not verified)
Monday, March 26, 2012 - 11:54pm
Permalink
Thanks so much, this is the
Thanks so much, this is the best tutorial online!
Michael (not verified)
Monday, April 8, 2013 - 11:41am
Permalink
Thank you very much. Wrestled
Thank you very much. Wrestled with this all day and finally got it going due to this page :)
Nitin (not verified)
Friday, July 19, 2013 - 9:04am
Permalink
Thank you very much
Thank you very much
Monu (not verified)
Tuesday, October 22, 2013 - 2:52pm
Permalink
Thanks a lot for this
Thanks a lot for this tutorial.
It is awesome.....!!!!
Sam (not verified)
Friday, January 3, 2014 - 9:30pm
Permalink
Thank You so very much ...
Thank You so very much ....You are a life saver!!!
Michael (not verified)
Sunday, November 29, 2015 - 5:15pm
Permalink
Thanks a lot, great tutorial!
Thanks a lot, great tutorial!
Ece (not verified)
Tuesday, December 1, 2015 - 10:03am
Permalink
Thank you! It's really
Thank you! It's really helpful article!
Ron Visbord (not verified)
Monday, June 20, 2016 - 2:20pm
Permalink
Thank you so MUCHHHHHH!
Thank you so MUCHHHHHH!
You just helped me setup my station after two days of struggling!
YES!
Add new comment