Friday, February 13, 2009

C/C++ in Eclipse on Windows

I recently helped a friend setup Eclipse on Windows Vista to develop C/C++ code. I remembered how painful it was for me the first time, so, I thought I would write a blog detailing the process to make life easier on others. Thankfully, the process has been greatly simplified since I first tried it a few years ago.

I. Download Eclipse

I am going to assume you do not already have Eclipse on your system. If you do, simply go download the CDT package as an add-on to accomplish this step. For those who do not already have Eclipse, you can get it simply by going to the Eclipse website at http://www.eclipse.org. Then click on the Downloads link. Here you will likely see a listing of several different packages. You will want the "Eclipse IDE for C/C++ Developers." All that has to be done then is to extract it to wherever it is going to be kept. I tend to put it in c:/program files/eclipse/, but that is just personal preference. To run Eclipse, simply execute eclipse.exe.

II. Install MinGW

I am going to provide a link to a file, but I highly recommend grabbing the file from their website in case anything new has been released. The reason I am providing a link at all is because they do not currently have an easily distinguishable link on their own website. Anyways, their website is currently located at http://www.mingw.org. From there, I have to scroll down until I see "HOWTO Install the MinGW (GCC) Compiler Suite" on the left under "Popular Content." Then there is a link under the "Using the Installer" category to this page. This installer saves a lot of hassle. Download the .exe and run it. I recommend the default location which is c:/mingw/ last I checked. Make sure to install GCC Core Components, C++, and MinGW-make.

Right now, you should be able to run the command c:/mingw/bin/gcc and get a polite error message about no input files. This means MinGW is working! However, to make it easier to use, you will want to add the mingw bin to your system path variable. How do you do this? That is exactly what I am writing this for. Open a command prompt by either pressing <windows key> + R, going to "Run..." in the start menu and entering "cmd", or type "cmd" in the search field in the start menu on Vista. Once you have a command prompt open, type
PATH = %PATH%;c:/mingw/bin/;

and hit enter. Now you should be able to simply type "gcc" and get the nice error message. Voila! MinGW is completely installed!

III. Configuring Eclipse

There is one final step: configuring eclipse to use mingw. Start up Eclipse and go to Window > Preferences at the top. Mine down through C/C++ > New CDT Project Wizard > Makefile Project. On the right, click on the tab "Builder Settings". Uncheck "Use default build command". This will activate a text field just below it labeled "Build command:" with the default value of "make". Replace it with "mingw32-make". Click "OK" at the bottom to save your settings.

Voila! You have just installed Eclipse to compile C/C++ code on Windows!

Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home