Introduction: How to Install MinGW GCC/G++ Compiler in Windows XP/7/8/8.1/10
Gcc and G++ are one of the best compilers for C and C++ in all platform. It's is lite, easy to use, and simple. But the packages and installation is not that simple. But it's clear and easy if you proceed one step at a time and do whatever is said in this tutorial. All screenshots are given. Do look at those if you are finding any steps difficult to complete.
I have a channel on youtube named Being Engineers. If you find this helpful so then please visit our channel and subscribe. It's helps a lot. link - www.youtube.com/c/being_engineers1
You can also watch this video that I made to get things work quickly. Same exact steps are shown there in the video -
If you are using windows 10 then there might be some problem executing the program. I will tell you the solution at the required step. So without making further delay let's start this tutorial.
Step 1: Download the Editor ( Notepad ++ )
You can use any editor you want to write and save your code. But from my experience I will recommend Notepad ++.
- Open google and search for notepad ++.
- Go to the first result and click on Download section. Find the latest version and download it.
- Open the downloaded file and install. It is very simple to install. If you have doubt then please refer to screenshots given here.
Open the software once to check if it's installed correctly. If yes move to next step.
Step 2: Download MinGW Package Installer
Fire up your browser again and follow the steps -
- Go to www.mingw.org
- Click on Download Installer in the upper right corner of the page.
- A new page will pop up and the download will start after some seconds. The downloaded file name will be "mingw-get-setup.exe"
- Open the installer and click on Install.
- Don't change the installation directory. leave it as it is and just click on continue.
- Download will start within the installer. So be patient and wait for it to complete. You can see the percentage there in the right hand box. When it's done click on continue.
- "MinGW Installation Manager" will open. There you can find all the packages. For our purpose check the "mingw32-gcc-g++" package and click on installation in the upper left corner.
- Click on apply changes and click on apply. The installation will start and it will take some time. When it is done and it displays " all changes were applied successfully. " then click on close.
To confirm that everything is done correctly just go to c:\MinGW\bin
There you should find both G++ and Gcc compiler. If not redo this process.
Step 3: Add Path Variables
Copy the address of the bin folder. That in most cases will be C:\MinGW\bin. Go to Control Panel\System and Security\System. Then follow the steps.
- Click on Advanced system settings.
- Under Advanced tab go to Environment variables.
- Search for 'Path' in system variable.
- Click on edit. In variable value, give a semicolon ( ; ) at the end and then paste the address of the bin folder that was copied earlier. Confirm it by clicking OK.
apply and close all windows.
Step 4: Write the Program
Now you can write any c or c++ program as you want. Save it in the bin directory in MinGW. For C programs the extension will be .c and .cpp for C++ programs.
I am giving one of each C and C++ programs here. So just to try download then and paste it directly in the bin folder or in a subfolder in bin.
link - https://goo.gl/PKmkYE
Step 5: It's DONE!!
Now to execute the programs you need to open the bIn directry. And then right click anywhere with the shift key pressed. You should see a option named ' open command window here '. If you can't do it then just Go to the upper left corner and click on File. Select 'open command prompt' and cmd window will appear on screen.
Now if have pasted the codes inside a subfolder in bin, then type in 'cd ' ( exclude <> ) and enter. If you have just pasted the code directly in bin, don't need to do anything.
WINDOWS 10 USER, DISABLE YOUR ANTIVIRUS OR ADD A EXCEPTION SO THAT YOUR ANTIVIRUS PROGRAM DON'T SCAN THE bin FOLDER.
To compile C program type 'gcc' and then type in the program name with the .c extension ( because gcc complies C programs ) with a space in between. Press Enter. Wait for some seconds before the same directory name comes again in the cmd screen. It means the program is compiled. To run just type 'a' and press enter.
Now you should see ' ****** HELLO WORLD ***** ' on the cmd screen. That is gven the code and that means everything has been done correctly.
For C++ everything is same except the compiler will be G++, not gcc. And the program extension will be .cpp.
So now you can write your codes and compile then easily. No heavy software, no time waste by creating projects. Everything is simple and clear.
If you have liked this tutorial then do check out our channel and don't forget to subscribe - www.youtube.com/c/being_engineers1