Grovix Lab

How to Install C++ with MinGW on Windows

Jul, 2024 Sun



Installing a C++ compiler on Windows can be an intimidating task for beginners. However, MinGW (Minimalist GNU for Windows) provides a straightforward way to set up a C++ development environment. This guide will walk you through the steps to install MinGW and configure your system to compile C++ programs.

Step 1: Download MinGW 

  1. Go to the MinGW download page: Open your browser and navigate to the MinGW download page on SourceForge.
  2. Download the MinGW Installer: Click on the "Download" button to download the MinGW Installation Manager (mingw-get-setup.exe). 

Step 2: Install MinGW

  1. Run the Installer: Locate the mingw-get-setup.exe file you downloaded and double-click it to run the installer.
  2. Install MinGW:
    • Click Install.
    • Choose the installation directory (default is C:\MinGW) and click Continue.
    • The installer will download the necessary files.

Step 3: Select and Install Packages

  1. Open the MinGW Installation Manager: Once the installation is complete, the MinGW Installation Manager will open. If it doesn’t, you can find it in your Start menu.
  2. Select Packages:
    • In the Installation Manager, expand the Basic Setup option.
    • Right-click on the mingw32-gcc-g++ package and select Mark for Installation. This is the GNU C++ Compiler.
    • Optionally, you can also select other packages you might need, such as mingw32-gcc-objc for Objective-C or mingw32-gdb for the GNU Debugger.
  3. Apply Changes:
    • Click on the Installation menu and select Apply Changes.
    • Click Apply on the pop-up window to start the installation of selected packages. 

Step 4: Configure Environment Variables

  1. Open Environment Variables:
    • Press Win + X and select System.
    • Click on Advanced system settings.
    • Click the Environment Variables button.
  2. Add MinGW to PATH:
    • In the System Variables section, scroll down and select the Path variable, then click Edit.
    • Click New and add the path to your MinGW bin directory (e.g., C:\MinGW\bin).
    • Click OK to close all dialog boxes.

Step 5: Verify Installation

  1. Open Command Prompt: Press Win + R, type cmd, and press Enter.
  2. Check GCC Version: Type g++ --version and press Enter. If the installation was successful, you should see the version of the installed GCC (GNU Compiler Collection).

Step 6: Write and Compile a Simple C++ Program

  1. Open a Text Editor: Open any text editor like Notepad or Visual Studio Code.
  2. Write a Simple Program:
    #include <iostream>
    	using namespace std;
    	int main() {
    	cout << "Hello, World!" << endl;
    	return 0;
    	}
    	
  3. Save the File: Save the file with a .cpp extension, for example, hello.cpp.
  4. Compile the Program:
    • Open Command Prompt and navigate to the directory where you saved hello.cpp.
    • Type g++ -o hello hello.cpp and press Enter.
    • This command compiles the hello.cpp file and creates an executable named hello.exe.
  5. Run the Program: Type hello and press Enter. You should see the output Hello, World!.

Congratulations! You have successfully installed MinGW and compiled your first C++ program on Windows. This setup will allow you to write, compile, and run C++ programs efficiently.

Sajad pp

Sajad pp 

I am an SEO specialist, a Computer Science student, Founder of Grovix Lab, and a backend developer.

Trending