Install GNU C/C++ Compiler on Windows
Install GNU C/C++ Compiler on Windows
This tutorial will install the GNU C/C++ Compiler on the Windows operating system. GNU is a recursive acronym for “GNU is Not Unix”. To install GCC on Windows, we need to install MinGW. MinGW stands for “Minimalist GNU for Windows.“ It is a minimalist development environment for native Microsoft Windows applications.
Check Install
Let’s first check if the GNU C/C++ Compiler is installed or configured on the system.
Open the Windows Command Prompt and run the following command.
\> g++ –version
If the output of the command is something like “g++ is not recognized as an internal or external command, operable program or batch file” then the GNU compiler is not installed or configured on the machine.
Download GNU C/C++ Compiler
To install MinGW, navigate to the SourceForge website. The installer is hosted on the SourceForge hosting platform.
- https://sourceforge.net/projects/mingw/
Click the Download button. The file would download to the browser download folder.
The filename would be mingw-<version>-setup.exe
or
mingw-get-setup.exe
Install GNU C/C++ Compiler
Locate the installer in the download folder and double-click on the MinGW install manager setup.
Click on the Install button.
The following install screen window will appear. The default install location is: C:\MinGW
We can choose to install the software in any directory. However, installing the software in the default install directory is always recommended.
Other install preferences.
- Graphical User Interface support
- Install for All users or just for you
- Start Menu folder
- Desktop shortcut icon
Click on the Continue button.
The following install screen will appear.
Choose the setup type. Ensure that the Basic Setup is selected on the left.
Select the basic packages:
- mingw32-base
- mingw32-gcc-g++
- msys-base.
Right-click on the package and select Mark for Installation. You can also select other packages for language support.
Choose Installation >> Apply Changes menu option to install the selected packages.
Click on the Apply button to install the packages.
The packages would be installed on the machine. We can add the bin subdirectory to the system PATH environment variable.
The command should display the command output. For example,
c:\mingw\bin>g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/6.3.0/lto-wrapper.exe
Target: mingw32
Configured with: ../src/gcc-6.3.0/configure –build=x86_64-pc-linux-gnu –host=mingw32 –with-gmp=/mingw –with-mpfr=/mingw –with-mpc=/mingw –with-isl=/mingw –prefix=/mingw –disable-win32-registry –target=mingw32 –with-arch=i586 –enable-languages=c,c++,objc,obj-c++,fortran,ada –with-pkgversion=’MinGW.org GCC-6.3.0-1′ –enable-static –enable-shared –enable-threads –with-dwarf2 –disable-sjlj-exceptions –enable-version-specific-runtime-libs –with-libiconv-prefix=/mingw –with-libintl-prefix=/mingw –enable-libstdcxx-debug –with-tune=generic –enable-libgomp –disable-libvtv –enable-nls
Thread model: win32
gcc version 6.3.0 (MinGW.org GCC-6.3.0-1)
That’s it. MinGW is now installed on the machine. We can compile and run C++ programs on the Windows machine.
Code::Blocks IDE
Another alternative to getting a GNU C/C++ compiler is to install an IDE that bundles the compiler. The easiest way to install a GNU compiler and an IDE for programming is to install Code::Blocks IDE.
Steps to install Code::Blocks IDE:
That’s it. The MinGW mingw32-gcc-g++ Compiler package implements the GNU C++ language compiler, which we require to compile C and C++ programs.