How To Install gcc Compiler Into Windows ?……

By | September 25, 2014
  • Setting up MinGW, GCC and Notepad++ on Windows

Downloading and Installing MinGW and GCC

Go to the MinGW download site

http://sourceforge.net/projects/mingw/files/

Go into the Installer folder and download the file mingw-get-setup.exe.

Run the downloaded file on your computer, accept all the default settings and continue. You should get the following screen:

pic1.png

Click on “Continue” and the MinGW Installation Manager will open and look like this:

pic2.png

Mark the following packages for installation

mingw-base

mingw-gcc-g++

Click on Installation->Apply Changes.

The installer will then download the needed packages. Your screen will look like this:

pic3.png

Once the installation is complete, the following confirmation screen will show:

pic4.png

Click on “Close” and exit the MinGW Installation Manager.

Download and Install Notepad++

Go to the Notepad++ download page:

http://notepad-plus-plus.org/download/v6.6.8.html

Download Notepad++ Installer.

Run the Installer and accept all the default options to install Notepad++.

You should now be able to run Notepad++ from the Start menu.

Setting up the system for programming

First of all create new folder on your disk to keep all the programs separately. Lets say you create it in your C drive can call it “code”.

Since MinGW was installed using default options, it should be in the C:\MinGW folder.

We will now create a short batch file to setup the command prompt to work with MinGW.  

Open Notepad++, create a new file with just the following command:

PATH=C:\MinGW\bin;%PATH%

Save the file as “setup.bat” in the folder c:\code.

Now you are ready to edit and compile programs.

  • How to edit and compile programs

Open Notepad++, write your program there and save it in the C:\code folder. Lets say the program is called “sample.c”.

Open the Windows Command Prompt. Change to the code folder by typing:

cd c:\code

Setup the command prompt using our batch file like this

C:\code>setup.bat

You can now compile your program like this:

C:\code>gcc sample.c

If there are errors, you will have to go back to Notepad++ to change the code.

If compilation succeeds, you will see the file a.exe created in the same folder.

Run the program like this:

C:\code>a.exe

By default every successful compilation will result in a.exe getting created and overwritten for every subsequent compile. If you want a different name for your compiled program, you should add the output file name to the gcc command like this:

C:\code>gcc -o sample.exe sample.c

And then run the program like this:

C:\code>sample.exe

That’s it !! You are ready to code.

Happy learning.

  • Tips

You only need to run the setup.bat file once when you open the command prompt. After that the settings will stay until you close that command prompt.

For fast switching between editing the code in Notepad++ and compiling on the command prompt, keep both open and keep switching using Alt+Tab. Like this screen:

pic5.png




Leave a Reply

Your email address will not be published. Required fields are marked *