NetBeans for C development in Windows
This tutorial is meant for people who want to develop applications in C using the NetBeans IDE. It uses the MinGW tools and not the cygwin tools.
I have found that cygwin is often used but I don't like/want to have a *nix environment installed in my system, I have my Ubuntu Linux for that. I also find that the few GBs that a cygwin installation can take up are somewhat abusive and really prefer the 65MB of a MinGW + MSys system. Other than that I like cygwin a lot ;)
This tutorial will tell you how to set up a C/C++ development environment in a windows machine. I have not tested it with the new Windows Vista and I don't know if MinGW and MSys are ready for Vista. This has been tested in Windows XP Professional Edition with SP3.
What I will not do is teach you how to write programs in C/C++ nor how to use the NetBeans IDE or the compiler and any of the tools that come with MinGW or MSys, just how to set them up.
TOC
- Introduction
- Needed tools
- Downloading and setting up
- Configuring the system
- Configuring the IDE - Netbeans 6.0 and above
- The "Goodbye world" program
- Notes
Introduction
Bringing the GNU tools into MS Windows requires some experience in development and the use of tool chains. It's not easy to just grab the GNU port for MS Windows and start working with it. Therefor I recommend you follow the instructions in how to use thestable release.
But the stable release of the MinGw project has a few problems, mainly the use of older versions of the GNU tool, the last stable GCC version used is 3.4.5, which is a bit old. It's something the MinGw developers have chosen to stick with: using only official ports of the GNU tools. And for those that need a bit more updated versions, I have tried to explain how to setup the MinGw + MSYS environment using an alternative distribution of the MinGw package and some of the proposed and candidate versions of MSYS.
Needed tools:
- Java JDK
- Netbeans IDE
- MinGw, MSYS, GDB and MSYS Supplementary Tools
- Nuwen MinGw - Only for those that need more updated tools.
Downloading and setting up
Using the stable releases is easiest way to install all the software. We will use the installers provided to configure everything
Java JDK and Netbeans IDE
Almost every computer has a Java Runtime Environment but JDK is not always installed. Although you only need JDK for Java development and not for C/C++, the Netbeans IDE needs to have a JDK in order to install and run. Use version 5.0 or above of the JDK.
You can find the Netbeans IDE on the netbeans page at http://www.netbeans.org. We will be using version 6.0, the Java JDK, which you need to run the IDE is available at http://java.sun.com. If you forgot do select the installer that includes the C/C++ module, you can install it from the update center, just go to Tools > Plugins > Avaliable Plugins, and find the one related to C/C++ development.
MinGW, MSYS, GDB and MSYS Supplementary Tools
Follow the download link from the MinGw project home page, http://www.mingw.org and find the installers for: Automated MinGW Installer, MSYS Base System, GNU Source-Level Debugger and MSYS Supplementary Tools.
Start by installing MingW using the automated installer, this is a small setup utility that will download the necessary files and install the MinGw system. It is better to place the automated installer inside a new folder as the downloaded files will be placed in the same folder as the installer.
After installing MinGw use the MSys installer, follow the instructions and when asked if you want to configure the installation, answer 'yes'. You'll need to provide the path to the MinGw installation folder, but notice that the back slash, '\', must be replaced by a forward slash, '/'.
Install the supplementary tools and the gdb, the supplementary tools go into the MSys base folder and the gdb is installed in the MinGw base folder.
This is an image of the folder I created and the files downloaded, I also placed the other installers inside this folder so that I would have everything I need at hand. If you save this folder, you don't need to download the stable release again as the automated installer will detect the files and use them instead of downloading new ones.
Configuring the system
The first thing to do is to configure your system path.
Go to the "Advanced" tab on Windows' System Properties and access the "Environment Variables"
On the "System Variables" select "Path" and press "Edit"
Edit the path to include:
- "
\1.0\bin" - "
\bin" - "
\lib" - "
\include"
Make sure make.exe's folder is the first in you path. Make.exe's folder is the "bin" in MSys' installation folder.
We can now test and see if both the MSYS console and the MS DOS console recognize GCC, lets issue the gcc --version command on them:
Configuring the IDE - NetBeans 6.0
The current version of C/C++ will detect most, if not all, settings. You won't have nothing to configure and you're options panel should look something like this:
Note that I deselected the option to install the Fortran compiler when I installed MinGw, that's what causes the red warning in the options panel, but as I don't want to develop using Fortran, the missing compiler is not important.
The "Hello World" program
Now if you create a new project, you can see the option for C/C++ Development. Lets see if it works...
We can see that our project was created successfully and that all important files are present. This was all created by the wizard and I will not go through them in this tutorial.
We right click the "Source Files" item, select "New", then "Main C File...". Just follow the wizard's instructions and a new C file with a main function will be created. And here we can see the code completion feature in action, trying to complete the parameters for the scanf I'm writing.
If we compile and run the project, everything works fine, so this is all that is needed to have a fully functional development environment using the GNU tools in MS Windows
No comments:
Post a Comment