Configure NetBeans IDE for Minimum GNU for Windows (MinGW)


In the previous article I described how-to get started with Minimum GNU for Windows (MinGW). In this article I demonstrate how-to utilize the MinGW toolchain from the Integrated Development Environment (IDE) NetBeans IDE.

NetBeans IDE lets you quickly and easily develop Java desktop, mobile, and web applications, as well as HTML5 applications with HTML, JavaScript, and CSS. The IDE also provides a great set of tools for PHP and C/C++ developers. It is free and open source and has a large community of users and developers around the world.

I assume that you’ve followed the instructions from the previous article.

  1. Install the latest version of NetBeans IDE from the official download page page. Chose the C/C++ download bundle (download size: 60 MB).
  2. Install NetBeans IDE to %PROGRAMFILES%\NetBeans 7.4.
  3. Start NetBeans IDE.
  4. Select the item Options below Tools in the menu bar. The dialog Options is opened.
NetBeans IDE: Options - General
  1. Select the tab C/C++. Ensure that the file paths are set as in the following screenshot (if you exactly followed the previous article).

    Note: I’ve also installed CMake, a cross-platform, open-source build system. CMake is not required to use the MinGW toolchain in NetBeans IDE.

NetBeans IDE: Options - C/C++ Build Tools
  1. Select the button OK. The dialog Options is closed.

And that’s it. Now we can create a C/C++ NetBeans project that is compiled and linked via the MinGW toolchain. I will demonstrate that by using the Hello World source code from the previous article.

  1. Select the item New Project… below File in the menu bar. The dialog New Project is opened.

    Select the item C/C++ from the Categories list box.

    Select the item C/C++ Application from the Projects list box.

NetBeans IDE: New Project (1/2)

Select the button Next >. 2. Enter hello_world into the text input Project Name, D:\dev into the text input Project Location and uncheck the checkbox Create Main File.

The source file from the previous article does already contain the main function.

NetBeans IDE: New Project (2/2)

Select the button Finish. The dialog New C/C++ Application is closed. 3. Open a command prompt (cmd.exe). Create a new directory src below the project.

   MD D:\dev\hello_world\src 4. Move the source file `` from the [previous article][1] to the directory `src`. On my machine the path of the file is `D:\dev\`.

   MOVE D:\dev\ D:\dev\hello_world\src\ 5. Switch back to NetBeans IDE. Right-click on the item *Source Files* below the project *hello_world* in the *Projects* window.    Select the menu item *Add Existing Item...* from the context menu, which opens the dialog *Select Item*.    Navigate to the file `D:\dev\hello_world\src\` and select the button *Select*. The dialog *Select Item* is closed.    After doing that, the project should be displayed as follows inside the *Projects* window of NetBeans IDE.
NetBeans IDE: Window Projects
  1. Now we should be able to build and run the project from inside NetBeans IDE. Select the menu item Run Project below Run in the menu bar (keyboard shortcut: F6). The following should be displayed in the tab hello_world (Build, Run) inside the Output window of NetBeans IDE:

     "/C/dev/MinGW/msys/1.0/bin/make.exe" -f nbproject/ QMAKE= SUBPROJECTS= .build-conf
     make[1]: Entering directory 'D:/dev/hello_world'
     "c:/dev/MinGW/msys/1.0/bin/make.exe"  -f nbproject/ dist/Debug/MinGW-Windows/hello_world.exe
     make[2]: Entering directory 'D:/dev/hello_world'
     mkdir -p build/Debug/MinGW-Windows/src
     rm -f "build/Debug/MinGW-Windows/src/hello_world.o.d"
     g++    -c -g -MMD -MP -MF "build/Debug/MinGW-Windows/src/hello_world.o.d" -o build/Debug/MinGW-Windows/src/hello_world.o src/
     mkdir -p dist/Debug/MinGW-Windows
     g++     -o dist/Debug/MinGW-Windows/hello_world build/Debug/MinGW-Windows/src/hello_world.o
     make[2]: Leaving directory 'D:/dev/hello_world'
     make[1]: Leaving directory 'D:/dev/hello_world'
     BUILD SUCCESSFUL (total time: 1s)

    The actual output of the application is displayed in the tab hello_world (Run) inside the Output window of NetBeans IDE:

     hello, world
     RUN SUCCESSFUL (total time: 42ms)

    Note: The last two lines are added by NetBeans IDE to indicate the status of the run. Both the return code (in this example 0, which is mapped to the string RUN SUCCESSFUL) and the total time of the execution (in this example 42ms) of the application are displayed.

Impressive. We have successfully imported our first C++ application into NetBeans IDE and built it with the MinGW toolchain.

The following web sites contain additional information about C/C++ development with NetBeans IDE:

Prepare for some more C++ stuff in the future!