How to install mingw on windows
How to install mingw on windows
How To install MinGW on Windows 10 (GCC & G++)
MinGW, a contraction of “Minimalist GNU for Windows”, is a minimalist development environment for native Microsoft Windows applications.
Downloading MinGW
3. As soon as you click download button on mingw website The following page will open in your browser (from the SourceForge.net web site).
4. The following exe file will be downloaded with the name mingw-get-setup.exe
5. Click mingw-get-setup.exe
6. Click install
7. Click continue
8. Click continue
9. The following pop-up window will appear. Pleas make sure that you selected all the check-boxes. e.g. mingw32-base, mingw32-gcc=g++, msys-base and so on.
10. Click on Installation > Apply Changes as shown in the picture below.
11. wait for the process to complete. once you see successful installation message close the window. Click Close.
12. Now we will set environment variable to use gcc and g++ command from terminal.
Windows 10 and Windows 8
Video : How To install MinGW on Windows 10 (GCC & G++)
Using GCC with MinGW
In this tutorial, you configure Visual Studio Code to use the GCC C++ compiler (g++) and GDB debugger from mingw-w64 to create programs that run on Windows.
After configuring VS Code, you will compile and debug a simple Hello World program in VS Code. This tutorial does not teach you about GCC, GDB, Mingw-w64, or the C++ language. For those subjects, there are many good resources available on the Web.
If you have any problems, feel free to file an issue for this tutorial in the VS Code documentation repository.
Prerequisites
To successfully complete this tutorial, you must do the following steps:
Install the C/C++ extension for VS Code. You can install the C/C++ extension by searching for ‘c++’ in the Extensions view ( ⇧⌘X (Windows, Linux Ctrl+Shift+X ) ).
Get the latest version of Mingw-w64 via MSYS2, which provides up-to-date native builds of GCC, Mingw-w64, and other helpful C++ tools and libraries. You can download the latest installer from the MSYS2 page or use this link to the installer.
Add the path to your Mingw-w64 bin folder to the Windows PATH environment variable by using the following steps:
Check your MinGW installation
To check that your Mingw-w64 tools are correctly installed and available, open a new Command Prompt and type:
If you don’t see the expected output or g++ or gdb is not a recognized command, make sure your PATH entry matches the Mingw-w64 binary location where the compilers are located. If the compilers do not exist at that PATH entry, make sure you followed the instructions on the MSYS2 website to install Mingw-w64.
Create Hello World
Add a source code file
Add hello world source code
Now paste in this source code:
Now press ⌘S (Windows, Linux Ctrl+S ) to save the file. Notice how the file you just added appears in the File Explorer view ( ⇧⌘E (Windows, Linux Ctrl+Shift+E ) ) in the side bar of VS Code:
You can also enable Auto Save to automatically save your file changes, by checking Auto Save in the main File menu.
The Activity Bar on the far left lets you open different views such as Search, Source Control, and Run. You’ll look at the Run view later in this tutorial. You can find out more about the other views in the VS Code User Interface documentation.
Note: When you save or open a C++ file, you may see a notification from the C/C++ extension about the availability of an Insiders version, which lets you test new features and fixes. You can ignore this notification by selecting the X (Clear Notification).
Explore IntelliSense
In your new helloworld.cpp file, hover over vector or string to see type information. After the declaration of the msg variable, start typing msg. as you would when calling a member function. You should immediately see a completion list that shows all the member functions, and a window that shows the type information for the msg object:
You can press the Tab key to insert the selected member; then, when you add the opening parenthesis, you will see information about any arguments that the function requires.
Run helloworld.cpp
Remember, the C++ extension uses the C++ compiler you have installed on your machine to build your program. Make sure you have a C++ compiler installed before attempting to run and debug helloworld.cpp in VS Code.
Open helloworld.cpp so that it is the active file.
Press the play button in the top right corner of the editor.
Choose C/C++: g++.exe build and debug active file from the list of detected compilers on your system.
After the build succeeds, your program’s output will appear in the integrated Terminal.
Your new tasks.json file should look similar to the JSON below:
Note: You can learn more about tasks.json variables in the variables reference.
The command setting specifies the program to run; in this case that is g++. The args array specifies the command-line arguments that will be passed to g++. These arguments must be specified in the order expected by the compiler.
The label value is what you will see in the tasks list; you can name this whatever you like.
The detail value is what you will as the description of the task in the tasks list. It’s highly recommended to rename this value to differentiate it from similar tasks.
Modifying tasks.json
Debug helloworld.cpp
The play button has two modes: Run C/C++ File and Debug C/C++ File. It will default to the last-used mode. If you see the debug icon in the play button, you can just click the play button to debug, instead of using the drop-down.
Explore the debugger
Before you start stepping through the code, let’s take a moment to notice several changes in the user interface:
The Integrated Terminal appears at the bottom of the source code editor. In the Debug Output tab, you see output that indicates the debugger is up and running.
The editor highlights the line where you set a breakpoint before starting the debugger:
The Run and Debug view on the left shows debugging information. You’ll see an example later in the tutorial.
At the top of the code editor, a debugging control panel appears. You can move this around the screen by grabbing the dots on the left side.
Step through the code
Now you’re ready to start stepping through the code.
Click or press the Step over icon in the debugging control panel.
This will advance program execution to the first line of the for loop, and skip over all the internal function calls within the vector and string classes that are invoked when the msg variable is created and initialized. Notice the change in the Variables window on the left.
In this case, the errors are expected because, although the variable names for the loop are now visible to the debugger, the statement has not executed yet, so there is nothing to read at this point. The contents of msg are visible, however, because that statement has completed.
Press Step over again to advance to the next statement in this program (skipping over all the internal code that is executed to initialize the loop). Now, the Variables window shows information about the loop variables.
Press Step over again to execute the cout statement. (Note that as of the March 2019 release, the C++ extension does not print any output to the Debug Console until the loop exits.)
If you like, you can keep pressing Step over until all the words in the vector have been printed to the console. But if you are curious, try pressing the Step Into button to step through source code in the C++ standard library!
When the loop has completed, you can see the output in the Integrated Terminal, along with some other diagnostic information that is output by GDB.
Set a watch
Sometimes you might want to keep track of the value of a variable as your program executes. You can do this by setting a watch on the variable.
To quickly view the value of any variable while execution is paused on a breakpoint, you can hover over it with the mouse pointer.
Customize debugging with launch.json
There are cases where you’d want to customize your debug configuration, such as specifying arguments to pass to the program at runtime. You can define custom debug configurations in a launch.json file.
You’ll then see a dropdown for various predefined debugging configurations. Choose C/C++: g++.exe build and debug active file.
VS Code creates a launch.json file, which looks something like this:
Change the stopAtEntry value to true to cause the debugger to stop on the main method when you start debugging.
From now on, the play button and F5 will read from your launch.json file when launching your program for debugging.
C/C++ configurations
If you want more control over the C/C++ extension, you can create a c_cpp_properties.json file, which will allow you to change settings such as the path to the compiler, include paths, C++ standard (default is C++17), and more.
You can view the C/C++ configuration UI by running the command C/C++: Edit Configurations (UI) from the Command Palette ( ⇧⌘P (Windows, Linux Ctrl+Shift+P ) ).
Here, we’ve changed the Configuration name to GCC, set the Compiler path dropdown to the g++ compiler, and the IntelliSense mode to match the compiler (gcc-x64)
You only need to add to the Include path array setting if your program includes header files that are not in your workspace or in the standard library path.
Compiler path
The extension uses the compilerPath setting to infer the path to the C++ standard library header files. When the extension knows where to find those files, it can provide features like smart completions and Go to Definition navigation.
The C/C++ extension attempts to populate compilerPath with the default compiler location based on what it finds on your system. The extension looks in several common compiler locations.
The compilerPath search order is:
Troubleshooting
MSYS2 is installed, but g++ and gdb are still not found
You must follow the steps on the MSYS2 website and use the MSYS CLI to install Mingw-w64, which contains those tools.
MinGW 32-bit
If you need a 32-bit version of the MinGW toolset, consult the Downloading section on the MSYS2 wiki. It includes links to both 32-bit and 64-bit installation options.
How to install MinGW64 (non of the approaches work)
I am trying to install MinGW64 on Windows 10. Here is what I tried:
Approach 1
I went to http://mingw-w64.org/doku.php/download/win-builds and from there to http://win-builds.org/doku.php/download_and_installation_from_windows where I downloaded Win-builds 1.5.0. I run the exe and let it install everything. When it gets to install mingw64 it says that the Download failed (no further information). What should I do?
Approach 2
I also downloaded mingw-w64-v7.0.0 from https://sourceforge.net/projects/mingw-w64/, extracted the zip but have not idea what to do with the contents:
Approach 3
In https://stackoverflow.com/a/48519212/4533188 it was said that should download from https://sourceforge.net/projects/mingw-w64/files/mingw-w64/, so I went there downloaded MinGW-W64-install.exe and ran it. The post says further
Once the compressed file downloaded, you have just to extract and copy/paste the MinGW64 folder( with the pre-compiled librairies) to your chosen folder ( in my case : C:\mingw64)
Approach 4
5 Answers 5
Trending sort
Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.
It falls back to sorting by highest score if no posts are trending.
Switch to Trending sort
Regarding your approaches:
For approach 4, this list of steps is slightly better than the list you linked
Installing the 32-bit and 64-bit C (gcc) and C++ (g++) Compilers on Windows
(These are different than the compilers included with Cygwin)
MinGW (Minimalist GNU for Windows), formerly mingw32, is a free and open source software development environment for creating Microsoft Windows applications.
Download the installer for MinGW from here:
The instructions on this page refer to version 7.1.0, build revision 1 of the MinGW tools. This is an older version than what we are currently using. As of September, 2019, the version that we are using is 8.1.0, build revision 0. So, if you see any screenshots below that refer to the older version, just substitute the newer version and everything should work fine.
Installing the 64-bit Version
Once you’ve downloaded the installer, follow the steps below to install and configure the tools.
If you want to be able to use the gcc/g++ compilers from any command prompt (which you most definitely do!), you’ll need to add the location of the bin folder to the path. Assuming that you have installed MinGW in c:\mingw as instructed above, you need to add:
When adding c:\mingw\mingw64\bin to your PATH, it MUST be the first entry in the PATH. Putting it somewhere else may cause the wrong compilers to be used (probably the compilers from the Cygwin utilities). Once you’ve modified your PATH, you should logout and log back in to Windows.
When you log back in, open a command prompt. You should now be able to type gcc or g++ from any command window and get the later version of the compilers.
To verify that you have correctly installed and configured your computer, open a command prompt and type this:
gcc (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0 Copyright (C) 2018 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Also, if you have already installed and configured the Cygwin utilities, if you type this at the prompt:
If you see this instead:
‘which’ is not recognized as an internal or external command, operable program or batch file.
it means that you have not installed the Cygwin utilities, or haven’t set the PATH for Cygwin correctly.
For students that are less experienced working with computers (e.g. installing developer software, configuring the PATH, working from the command prompt, etc.) you may need to visit the Academic Support Center for more help. The students working there can help you ensure that your computer is configured properly. Or, you can just ask a student that is more familiar with Windows.
Installing the 32-bit Version (Optional)
It’s unlikely that anyone is using a 32-bit computer these days, so it is not necessary to install this version. I’m leaving the instructions here for historical context.
Done. Again, almost.
The rest of this guide assumes that you installed the compiler to c:\mingw32 during the installation.
Currently, when you type g++ from the command line, you will run the 64-bit version of the MinGW g++ compiler. You want to continue to do that. To run the 32-bit version, you will need to create a batch file called g++32.bat and put it in your PATH somewhere. (You should have created a C:\utils directory on your computer to put your add-on programs. This directory should be the first directory in your PATH.) The contents of the batch file should look like this:
You can create the batch file with any text editor (e.g. notepad++) or, you can download the batch file here: g++32.bat (recommended). You need to download this file, not click on it and run it (the default in some versions of Windows). There is also a batch file for gcc here: gcc32.bat. Use this to compile 32-bit C programs.
Once you’ve downloaded the batch to (or created it in) some directory in your PATH, you can check that it’s correct by typing this from any directory:
If everything was setup properly, you should see this message in the console:
When running the executable program, if you get an error saying something like:
«The program can’t start because » is missing from your computer. «
«The application was unable to start correctly (0xc000007b). «
then you will need to put the bin directory of the 32-bit MinGW compiler at the end of your PATH. If you installed it to the location recommended in these notes, that directory is C:\mingw32\mingw32\bin. The name of the missing DLL file may be something like libwinpthread-1.dll, or libgcc_s_dw2-1.dll, or some other file.
Note: If you put the bin directory somewhere other than the end of your PATH, it may interfere with your 64-bit compiler causing it to no longer work.
When running the executable program, if you get an error message that looks like this:
Then you need to statically link the executable. Add this option (in bold) to the command line:
This will make the executable much bigger, but it should avoid the error.
This is also trivial to override the compiler in your makefile. If your makefile has a macro like this (which all of your makefiles should have)
To verify that your program is really a 32-bit executable, use the file command (part of the Cygwin utilities). For example, this command:
Note to Linux and Mac users: Building a 32-bit program under Mac or Linux is trivial. You simply add a -m32 option to the command line. For example:
Incidentally, to create a 64-bit executable, you can use -m64, but since this is the default, you don’t have to provide it to the compiler. If you run the file command on Linux, you would see something like this (with possibly more information displayed)
MinGW C++ Download and Installation
MinGW means Minimalist GNU for Windows: GNU is a source of open source programming tools (GNU stands for GNU is Not Unix).
In this handout you will download the files needed by GNU C++; in the next you will download a version of Eclipse that is already set up to use MinGW.
You may want to print these instructions before proceeding, so that you can refer to them while downloading and installing MinGW. Or, just keep this document in your browser. You should read each step completely before performing the action that it describes.
MinGW
Downloading
The following page will appear in your browser (from the SourceForge web site).
This file should start downloading in your standard download folder. This file is only 85KB so it should download very quickly.
The file should appear as
Terminate the window browsing the SourceForge web site.
Installing
The following pop-up window will appear.
The following pop-up window will appear.
The following pop-up window will appear.
You can install this software anywhere, but I recommend installing it in the default directory: C:\MinGW.
The following pop-up window will appear, showing the downloading progress. After about a minute, it should appear as follows.
The following pop-up window will appear. Ensure on the left that Basic Setup is highlighted. Click the three boxes indicated below: mingw32-base, mingw32-gcc=g++, msys-base. After clicking each, select Mark for selection. This window should appear as follows.
The following pop-up window should appear
The following pop-up window should appear
The following pop-up window will appear, showing the downloading progress.
After a while (a few minutes to an hour, depending on your download speed), it should start extracting the donwloaded files. A few minutes after that, the following pop-up window should appear.
When done it should look like