Deborah R. Fowler
GNU (MinGW)
compiler on Windows for C++
Updated on Feb 25 2014Updated on Dec 1 2017
Update on April 16 2021
Installing
the GNU compiler on Windows:
If you do not wish to use an IDE
such as Visual Studios, you can also compile in a more "linux
like" manner on windows using the gnu (mingw) compiler.To install this (modified from Page 11 of C++ Programming in easy steps) do the following (tested again on Windows 10 personally 12/1/2017 and 4/16/2021):
1. Go to sourceforge.net/projects/mingw
2. Hit the "Download" green button
3. Save and launch the file to install but be sure to select "C++ Compiler" as it defaults to off under Select Components (see below under Troubleshooting)
4. Include the path on windows, and you can then use the gnu-compiler in a command prompt (cmd) window
NOTE: To include the path on Windows 10 you need to:
- search for Control Panel in the start menu, and search "Envi"
- select edit the systems environment variables - this will bring up a dialog box
- in the lower right corner, click Environment Variables
- edit the "path"
under
"System variables" to include C:\MinGW\bin (you
can use new, edit or just click in the empty space)
- click okay and look to see that C:\MinGW\bin; ... is in your path, then click okay again
Troubleshooting:
If you see libgmp-10.dll is missing make sure you have checked that base as well as the C++ option are installed:Test your compiler by using a simple hello world example. Puruse to the directory (cd to the path of where the files lives). Ms-Dos is similar to linux, however dir is used instead of ls to list files
ie. in any text editor save a file labeled helloworld.cpp with the following content:
Using the GNU compiler on Windows:
// C++ Hello World Example
Program#include <iostream>
using namespace std;
int main()
{
cout << "Hello World" << endl;
return 0;
}
To compile this, start a command prompt window and type c++ helloworld.cpp -o helloworld.exe
Run helloworld.exe or simply helloworld
Using the GNU compiler with a Makefile
You could also compile using a Makefile by running the command mingw32-make with a Makefile in the directory. A simple makefile would look as follows (note the white space is a TAB). Typing mingw32-make would execute the command line.
hello: helloworld.cpp
c++ -o helloword helloworld.cpp
Using the GNU compiler on Windows with OpenGL/freeglut: click here