27 Nov 2017

Hello world! C++ application in NetBeans IDE 8.2 (Win10 + MinGW-W64)

This post is dedicated to simple "Hello world!" application project in NetBeans IDE 8.2, that is compiled as 32-bit and 64-bit application using MinGW. This tutorial summarizes my approach and it is focused to make things work, but it may not be the best approach...


Prerequisites for this task

  • NetBeans IDE 8.2 for C/C++
  • MinGW tools
  • MinGW-W64 tools
My operating system is Windows 10, 64-bit version. The first step is to download and install NetBeans IDE, in my case it is NetBeans IDE 8.2. Then I have installed Mingw and MinGW-w64. In NetBeans main menu Tools/Options/C/C++ I have these two configurations:

MinGW32 (for 32-bit applications)



MinGW-W64




Hello world! project

Create a new C/C++ Application project


Name the project as you wish, in my case it is MySampleApp. I use MinGW32 tool collection as default, but you can use MinGW-W64 and make 64-bit application first.


Modify the default main.cpp file and add Hello world! message using printf function from stdio.h.

Now open the project Properties by right-click on project root. Since we want to make 32/64 bit application versions, click on Manage Configurations... Select Debug and duplicate it for 64-bit version. Do it for Release too. For example you may have configurations with these names:


The next step is to set an Architecture. Select both 32-bit configurations.


In C/C++ Compiler category, set Architecture to 32 bits. In Compilation Line, add Additional Options 

-static-libgcc -static-libstdc++


Same task for 64-bit configurations, select both set Architecture to 64 bits.



Moreover, in Build category, select MinGW-W64 in Tool collection field.


Now select All configurations, go to Run category and set Standard Output to Console Type


Compile and run the project


32-bit version


Select Debug configuration (32-bit) and Build the project.


If no errors, you can run the application with this output. 


Same result should be achieved in Release (32-bit) configuration.


64-bit version


Select Debug_64bit configuration and Build the project. Compilation output with no errors is like this



Application runs with same output


Summary


This post presents the simple console project that is configured for 32/64 bit versions of operating system. The main focus of this tutorial is to test, if the MinGW tool collections are configured correctly in NetBeans IDE. Presented project could be a basis for more complex applications.

No comments:

Post a Comment