Run your first program in MinGW Compiler


Advertisements

This post will help you in running your first program in MinGW compiler and will also give some description regarding it’s installation.

So, starting with the post I’m listing down the topics which I’ve covered:

  • What is MinGW compiler
  • Comparison with Cygwin
  • Installation
  • Steps

What is MinGW Compiler?

  • MinGW is Minimalist GNU for Windows
  • This compiler is used in the development of Windows Application.
  • It was developed by Colin Peters.
  • It’s initial realease came it the year 1988.

Comparison with Cygwin

MinGW being a minimalist GNU will never provide POSIX runtime environment for
POSIX application development on Windows.

POSIX(Portable Operating System Interface) is a standard which provides compatibility
between Operating Systems

Cygwin provides POSIX application deployment.

Installation

For setting up MinGW environment and running the program, I’m using the following:

  • Windows 7 OS
  • MinGW compiler
  • Text Editor i.e Notepad

 

Now, install MinGW from the following link:  Download

While downloading you will come across these screenshots:

 

 

 

Steps:

Now, the following steps show you how to run your first program in MinGW compiler:

  • Open MinGW shell from the following link (assuming that you installed it in C: drive):
  • C:\MinGW\msys\1.0
  • Now, after opening MinGW shell, reach this location by following the steps shown under below screenshot:

    • Create a new txt file in “bin” directory and save it as “amitprogram1.c”

      Write the following simple code to add two numbers (showing this program for the sake of simplicity):

  • Now, enter the following command:
    gcc amitprogram1.c –o amitprogram.exe
    -o shown in the command defines the name of the output file generated. The above command will compile successfully and .exe file will generate:
  • Now, run it successfully by entering “amitprogram1”, output can be seen here:
  • Finally, you’ll successfully execute your first program in MinGW compiler.
    For executing your c++ program, just change “gcc” to “g++” i.e

    g++ amitprogram1.c –o amitprogram.exe

In this way you can run your first program in MinGW compiler.

amit2012

amit2012

Senior Research Fellow, Programmer, Technical Writer
Guy passionate about learning, exploring new things.
amit2012

Latest posts by amit2012 (see all)

Advertisements