If you are in search of free compiler to execute your C++ programs then MinGW is good choice.MinGW offers command line version of the compiler,if you are not comfortable with command-line style compiler then you can use Dev-C++,which uses MinGW internally.This guide explains the installation & execution of MinGW under windows platform.
What is MinGW ?
MinGW is is a command-line C/C++ compiler based on the GNU GCC project.MinGW comes with almost every library that you need to create command-line or GUI based application on any windows platform.Some exceptions are there like it won’t work under win 3.1 & old DOS machines.As MinGW doesn’t comes up with IDE,you have to use Notepad or your favourite text editor to write the programs & then execute them from command line.
First thing you need to do is type http://www.mingw.org/ in your browser.Then Go to download page.Now,there are two methods to install the MinGW on your computer.
Automatic installer,that allows you to download the MinGW without knowing the packaging & compiler details.After running the installer,Select a folder where you would like to install MinGW( e.g.”C:/MinGW”). It’s good if you don’t use a folder that contains spaces.Once the files are copied, click Finish to finalize the installation.
If you don’t want to use the automatic installer then you can manually downlaod the files & install the MinGW.Here is the list of minimum packages you need to install:
Each of these packages are followed by version number (e.g.w32api-3.6.tar.gz).So choose the newer version from the download files list.Optionally you can download the packages like :
The packages you download are the gzipped tarballs,so you need gzip or simmilar software to decompress the files.You can use Zipgenius or (Gzip & Tar) to decompress these files.So extract these files under path like ( “C:/Mingw” OR “D:/mingw”,try to create folder that doesn’t contain spaces).
Before using the MinGW you need to set the PATH environment variables so that the Command Prompt understands how to find the compiler executable program.To set the PATH variable follow the procedures below:
For Windows 2K/XP & above
- Right click My Computer > Properties.
- In system properties >Advanced Tab > ” Environment Variable” button at bottom.
In Envirement Variable dialog,Find the “PATH” variable in system variables list,and click “Edit”.When Edit varibles dialog,add the following lines :
(or whatever directory you’ve created for mingw,just point to the bin directory)
Don’t forget the semicolon.Click ok.Close all the dialog windows.
For win9x system
Find the file named as AUTOEXEC.BAT in C:/ drive.If you’ve installed the files in another drive then create the file manually. Now add the following line in that file:
(Chnage the path as per your MinGW directory)
Save the file.Now you’re done with the MinGW configuration.It’s time to test the envirement for Mingw.Open up the command prompt window (w2k/XP users) or DOS prompt (win9x),type the following:
You’ll see something like this in command prompt:
g++ (GCC) 3.4.5 (mingw special)
Copyright (C) 2004 Free Software Foundation, Inc.
This means that you’ve successfully installed the Mingw on your computer.
If not you’ll see something like this:
'g++' is not recognised as an internal or external command.
That means you’ve made mistake setting PATH.So go back check the path & again test the version at command prompt.If you’ve got no errors then lets try to compile and run programs.so write simple program for hello world,save it with .cpp extention.In command prompt switch yourself to the directory where the .cpp file exist.
To compile, use the command:
e.g if you are in directory called sample where you’ve saved the file “hello.cpp”.
C:/sample>g++ hello.cpp -o hello.exe
Here,-o switch is used to specify the executable name to be set as”hello.exe” instead of “a.exe”.You can run your program,by typing “hello” in command prompt pointing to the same directory.
Here are some great resources that can answer any of your MinGW questions. I know I could not have written this article without consulting them several times.