avatar

Andres Jaimes

Installing gcc/g++ using MinGW and NetBeans in Windows

By Andres Jaimes

C and C++ languages are everywhere. All operating systems use them. People usually choose them because of their limitless power, velocity of execution, great portability and much more. In this tutorial I will show you how to install a C/C++ development environment under Windows. By the way, MinGW includes other compilers for languages like c, c++, objective c fortran and ada.

 

Install MinGW

  • Go to the MinGW website and look for the download link. You can get it directly from SourceForge.
  • Start the installation.
  • Under Repository Catalogues, select Download latest repository catalogues. You can also keep the Use pre-packaged repository catalogues if your package includes a recent snapshot.
  • Select your installation path. Try to select one that is easily accesible from the command line.
    Note: I have changed my default installation directory to C:optMinGW. This is completely optional.
  • Select C, C++ and other languages you want to install, plus the MSYS Basic System. MSYS includes several handy shell tools like bash, make and grep that will allow you to build applications that depend on UNIX tools to be present.
  • Continue through the wizard screens and press Install.
  • If you chose the option to download the latest repositories, it will take a little bit more.
  • In order to access your compilers from any directory in your system you now have to add the following directories to your PATH environment variable:

 

C:optMinGWbin
C:optMinGWmsys1.0bin

 

Install Netbeans

  • Go to the Netbeans website and select Download
  • ****Choose an option that includes C/C++
  • Install it
  • Now that Netbeans is installed, we need to configure it to use MinGW. You can do that by going to Tools > Options and selecting the C/C++ tab. If your environment variables are correctly set, Netbeans will find your MinGW installation and will configure itself. The following screen shows how it looks:

Press Ok to accept the changes.
Everything is ready. It is time to test it.

 

Testing the Environment

In Netbeans:

Go to File > New Project. Under Categories select C/C++ and then, under Projects, select C/C++ Application.

Select a project name and folder locations. In my case I’m going to name it CppTest. Press Finish.

After this you should have a project with two files in it. Double click main.cpp to edit it.

What would be a tutorial without a HelloWorld program… Well, type the following program in your editor and press the Execute button (the one that looks like a Play button). If everything goes fine, you should see at the bottom a message greeting the world.

That is it. Now go ahead and create some amazing code.