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.
I assume that you’ve followed the instructions from the previous article.
- Install the latest version of NetBeans IDE from the official download page page. Chose the C/C++ download bundle (download size: 60 MB).
- Install NetBeans IDE to
- Start NetBeans IDE.
- Select the item Options below Tools in the menu bar. The dialog Options is opened.
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.
- 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.
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.
Select the button Next >.
into the text input Project Name,
into the text input Project Location and uncheck the checkbox Create Main File.
The source file
from the previous article does already contain the
Select the button Finish. The dialog New C/C++ Application is closed.
Open a command prompt (
). Create a new directory
below the project.
Move the source file
from the previous article to the directory
. On my machine the path of the file is
MOVE D:\dev\hello_world.cc D:\dev\hello_world\src\hello_world.cc
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
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.
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
"/C/dev/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf make: Entering directory 'D:/dev/hello_world' "c:/dev/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/hello_world.exe make: 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/hello_world.cc mkdir -p dist/Debug/MinGW-Windows g++ -o dist/Debug/MinGW-Windows/hello_world build/Debug/MinGW-Windows/src/hello_world.o make: Leaving directory 'D:/dev/hello_world' make: 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:
1 2 3
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
, which is mapped to the string
) and the total time of the execution (in this example
) 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:
- NetBeans IDE - C and C++ Development
- C/C++ Application Learning Trail - NetBeans Tutorials, Guides and Articles
Prepare for some more C++ stuff in the future!