Configuring the NetBeans IDE for C/C++/Fortran

This document provides information about downloading, installing, and configuring C/C++ support in the NetBeans IDE. Before you can develop in C/C++, the NetBeans IDE requires the C/C++ plugin module, and third party C/C++ compilers, make utilities, and debuggers.

Contents

Content on this page applies to NetBeans IDE 6.7

To follow this tutorial, you need the following software and resources.

Software or Resource Version Required
NetBeans IDE 6.7
Java Development Kit (JDK) version 6 or version 5

Enabling C/C++/Fortran in the IDE

The NetBeans IDE is a dynamic modular IDE, which means you can change it by adding and removing modules of the program. You can add functionality by installing plugin modules, or remove functionality by uninstalling plugin modules. See the NetBeans IDE online help for more information about plugins.

If you want to work with C, C++, or Fortran programs in the NetBeans IDE, your NetBeans installation must include the C/C++ plugin.

Although the plugin is named C/C++, it also includes support for Fortran programming.

If you have not yet installed NetBeans IDE 6.7

If you have not yet installed the NetBeans IDE, download either the C/C++ bundle or the All bundle from NetBeans IDE 6.7 Download Page. If you will not be using other languages such as Java and Ruby, you should download the C/C++ bundle.

If you have NetBeans IDE 6.7 but do not know if you have the C/C++ plugin

If you already have NetBeans IDE, determine if your NetBeans IDE includes the C/C++ plugin already, by selecting File > New Project. If C/C++ is listed as one of the Categories, you have the C/C++ plugin module. You should skip to the section Installing and Setting Up the Compilers and Tools.

If you have NetBeans IDE 6.7 without the C/C++ plugin

If your NetBeans IDE does not show a C/C++ project category when you select selecting File > New Project, complete the following steps to add the C/C++ plugin module to the IDE.

  1. If your network uses a proxy, choose Tools > Options in the IDE, select Manual Proxy Settings, enter the HTTP Proxy and Port for your proxy, and click OK.
  2. Choose Tools > Plugins.
  3. In the Plugins dialog box, click the Available Plugins tab, and scroll to the C/C++ category.
  4. Select the C/C++ checkbox and click Install to start the NetBeans IDE Installer.
  5. In the NetBeans IDE Installer, click Next.
  6. Read the license agreement, select the checkbox to accept the terms of the license agreement, and click Next.
  7. Click Install.
  8. After the installation completes, select either Restart IDE Now or Restart IDE Later and click Finish.

Installing and Setting Up the Compilers and Tools

The Netbeans C/C++ module requires a C compiler, C++ compiler, make utility, and gdb debugger. See the following instructions for the platform of your development system.

Windows
Solaris OS
OpenSolaris OS
Linux
Macintosh OS X

Windows

The NetBeans C/C++ module has been tested with compilers from Cygwin and MinGW. You should install either Cygwin or MinGW compilers, but not both.

If you want to use Qt with Windows, you must install MinGW.

Cygwin Compilers and Tools
MinGW Compilers and Tools

Cygwin Compilers and Tools

The NetBeans C/C++ module has been tested with the following compilers and tools from Cygwin.com.

Software or Resource Version Tested Description
cygwin1.dll 1.5.21 Cygwin Linux-like environment for Windows
gcc 3.4.4 Cygwin C compiler
g++ 3.4.4 Cygwin C++ compiler
gdb 6.8 Cygwin GNU debugger
make 3.81 Cygwin make utility

If you already have the Cygwin gcc and g++ compilers, GNU make, and gdb debugger installed on your Windows system and your path is set up correctly to find them, make sure that you have the correct versions.

To check the versions of your Cygwin compilers and tools:

  1. Check the version of Cygwin environment by typing the following commands at a Windows command prompt:

     C:\> cygcheck -c cygwin
    
  2. Check the versions of the Cygwin gcc and g++ compilers, make, and gdb by typing the following commands at a Windows command prompt:
    C:\> gcc --version
    C:\> g++ --version
    C:\> make --version
    C:\> gdb --version
    

If you have the correct versions, then no further setup is necessary. See Verifying the Installation to verify that the tools are installed correctly for the NetBeans IDE.

To install the GNU gcc and g++ compilers, make, and gdb debugger from cygwin.com:

  1. Download the Cygwin setup.exe program by clicking the Install or Update Now! icon in the middle of the page, or by clicking this direct setup.exe link.
  2. Run the setup.exe program. Accept the defaults until you reach the Select Your Internet Connection page. Select the option on this page that is best for you. Click Next.
  3. On the Choose Download Site page, choose a download site you think might be relatively close to you. Click Next.
  4. On the Select Packages page you select the packages to download. Click the + next to Devel to expand the development tools category. You may want to resize the window so you can see more of it at one time.
  5. Select each package you want to download by clicking the Skip label next to it, which reveals the version number of the package to download. At a minimum, select gcc-core: C compiler, gcc-g++: C++ compiler, gdb: The GNU Debugger, and make: the GNU version of the 'make' utility. Packages that are required by the packages you select are automatically selected as well.
  6. Click Next to connect to the download site and download the packages you selected, and click Finish when the installation is complete.
  7. Now add the Cygwin compiler directory to your path to enable NetBeans IDE to find the tools collection:

    1. Open the Control Panel (Start > Settings > Control Panel) and double-click System.
    2. Select the Advanced tab and click Environment Variables.
    3. In the System Variables panel of the Environment Variables dialog, select the Path variable and click Edit.
    4. Add the path to the cygwin-directory\bin directory to the Path variable, and click OK. By default, cygwin-directory is C:\cygwin. Directory names must be separated with a semicolon. Your edited path should look something like %SystemRoot%\system32;%SystemRoot%;C:\Program Files\QuickTime\QTSystem;C:\cygwin\bin
    5. Click OK in the Environment Variables dialog and the System Properties dialog.
    6. See Verifying the Installation to verify that the tools were installed correctly for the NetBeans IDE.

MinGW Compilers and Tools

NetBeans IDE 6.7 was tested with Minimalist GNU for Windows (MinGW) and the Minimal System (MSYS) Unix-like environment. Versions tested and installation instructions are shown below.

Software or Resource Version Tested Description
gcc 3.4.5 MinGW C compiler
g++ 3.4.5 MinGW C++ compiler
gdb 6.8 MinGW GNU debugger
make 3.79.1 MSYS make utility
Note that MinGW make is not supported

To install the GNU compilers, make, and gdb debugger from mingw.org:

  1. Log in to Windows using an account with "computer administrator" privileges.
  2. Download the self-extracting installer from How To Install the MinGW (GCC) Compiler Suite on mingw.org or for convenience you can download from this direct link to MinGW-5.1.4.exe.
  3. Run the MinGW-5.1.4.exe installer in Windows.
  4. In the MinGW installer, accept the defaults until you get to the Choose Components page.
  5. On the Choose Components page, select the g++ compiler. The gcc compiler is automatically included in the installation so it is not a selectable component.
  6. Do not select MinGW make, as you need to use the make from MSYS instead, which is downloaded separately. Click Next.
  7. Use the default C:\MinGW as the destination folder if possible to minimize any potential difficulty with using the compilers from another location.
  8. Click Install to install the MinGW tools, then click Next, then click Finish.
  9. Add the C:\MinGW\bin directory to your path, as described in Environment Settings in the MinGW wiki.
  10. See the installation instructions for MSYS at the MinGW MSYS wiki. You only need to install the MSYS 1.0 files. You do not need to install the DTK or the core files mentioned in the wiki page.
  11. For convenience, you can download from this direct link to MSYS-1.0.10.exe
  12. Make sure you are using a Windows account with "computer administrator" privileges when you install MSYS. The NetBeans IDE might have issues when you try to build and run projects later if MSYS is installed under a limited user account.
  13. Run the MSYS-1.0.10.exe installer and accept the defaults.
  14. To install the gdb debugger, download from this direct link to gdb-6.8-mingw-3.tar.bz2. You must have a Windows zip utility such as gzip, 7-zip, or WinZip to extract this gdb archive.
  15. Unzip the gdb-6.8-mingw-3.tar.bz2 to your C:\MinGW directory so that the gdb executable is installed into your C:\MinGW\bin directory.
  16. See Verifying the Installation to verify that the tools were installed correctly for the NetBeans IDE.

Solaris OS

On the Solaris OS, you can use GNU tools or Sun Studio tools. The GNU tools are included in Solaris 10 OS in the /usr/sfw/bin directory by default. The Sun Studio software is a suite of developers tools that are free to download. The Sun Studio compilers are optimized for Sun hardware, and make it easier to produce performance tuned Solaris binaries.

If you are using OpenSolaris, see OpenSolaris OS.

NetBeans IDE 6.7 has been tested with the following compilers and tools.

Software or Resource Version Tested Description
cc 5.9 and 5.10 Sun Studio 12 C compiler
CC 5.9 and 5.10 Sun Studio 12 C++ compiler
gcc 3.4.3 GNU C compiler
g++ 3.4.3 GNU C++ compiler
gdb 6.6 and 6.8 GNU debugger
gmake 3.81 GNU make
make 3.81 Solaris make
dmake 7.8 and 7.9 Sun Studio 12 distributed make utility

Sun Studio 12 Compilers

If you want to use the Sun Studio 12 compilers in Solaris 10 OS:

  • If you have Sun Studio 12 software installed, ensure that /installation directory/SUNWspro/bin is in your path before you start the NetBeans IDE. The default location on Solaris 10 OS is /opt/SUNWspro/bin
  • If you do not have Sun Studio 12 software installed, you can download it free at http://developers.sun.com/sunstudio/downloads/.

To download and install the Sun Studio 12 compilers:

  1. Create a directory for the downloaded file. You must have write permission for this directory.
  2. Download the file for your platform into the download directory.
  3. Go to the download directory, and uncompress and untar the downloaded file.
    bzcat filename | tar xvf -
    
  4. Follow the instructions in Chapter 2 of the Sun Studio 12 Quick Installation (English, Japanese, Simplified Chinese) guide to install the C compiler, C++ compiler, and required Solaris patches.
  5. Edit your PATH to add the path to the Sun Studio software before starting the NetBeans IDE.
  6. See Verifying the Installation to verify that the tools were installed correctly for the NetBeans IDE.

GNU Compilers and GNU make

If you want to use the GNU compilers and GNU make:

  • If you have a standard installation of the Solaris 10 OS, the compilers and gmake are installed in /usr/sfw/bin. Make sure that this location is in your PATH before starting the NetBeans IDE.
  • If the compilers and gmake are not installed on your system, you can download them from http://www.sunfreeware.com.

To download and install the GNU compilers and make utility

  1. Download gcc and make.
  2. If the download zip files are not automatically extracted during download, unzip them with gunzip.
  3. Install the packages with the pkgadd command.
  4. Make sure to include the GNU compiler directory and the GNU make directory in your path before starting the NetBeans IDE.

gdb Debugger

Whether you use the Sun Studio compilers and Solaris make or the GNU compilers and GNU make, you must have the gdb debugger to debug applications in NetBeans IDE. You can download gdb from http://www.sunfreeware.com.

To download and install gdb:

  1. Download gdb 6.6 or 6.8.
  2. If the download zip file is not automatically extracted during download, unzip it with gunzip.
  3. Install the package with the pkgadd command.
  4. Make sure to include the path to gdb in your PATH before starting the NetBeans IDE.
  5. See Verifying the Installation to verify that the tools were installed correctly for the NetBeans IDE.

OpenSolaris OS

On the OpenSolaris OS, you can use GNU tools or Sun Studio tools. Both tool collections can be easily downloaded using the pkg command or Package Manager utility from the OpenSolaris desktop.

NetBeans IDE 6.7 has been tested with the following compilers and tools.

Software or Resource Version Tested Description
cc 5.9 and 5.10 Sun Studio 12 C compiler
CC 5.9 and 5.10 Sun Studio 12 C++ compiler
gcc 3.4.3 GNU C compiler
See the NetBeans IDE 6.7 release notes for information about NetBeans and gcc in the OpenSolaris OS.
g++ 3.4.3 GNU C++ compiler.
See the NetBeans IDE 6.7 release notes for information about NetBeans and gcc in the OpenSolaris OS.
gdb 6.6 GNU debugger (note that gdb 6.3 is in the OpenSolaris
repository, and is not supported by NetBeans IDE 6.7).
gdb 6.6 was built on OpenSolaris for testing purposes.
See the NetBeans IDE 6.7 release notes for information about NetBeans and gdb in the OpenSolaris OS.
gmake 3.81 GNU make
make - Solaris make
dmake 7.8 and 7.9 Sun Studio 12 distributed make utility


To download and install the Sun Studio 12 software and gdb debugger:

  1. Type the following in an OpenSolaris terminal window:
    $ pfexec pkg install sunstudio gdb
  2. Edit your PATH to include the path to the Sun Studio compilers before starting the NetBeans IDE. The path is /opt/SunStudioExpress/bin or /opt/SunStudio/bin.

To download and install the GNU gcc compilers and gdb debugger:

  1. Type the following command in an OpenSolaris terminal window:
    $ pfexec pkg install SUNWgcc SUNWgccruntime gdb  
  2. Links to the compilers and gdb are installed in /usr/bin, which is most likely already on your path. If /usr/bin is not on your path, edit your PATH to add it before starting the NetBeans IDE.

See the OpenSolaris wiki page Installing C++, Fortran Development Tools for more information.

Linux

On Linux platforms, you can use GNU tools or Sun Studio tools.

NetBeans IDE has been tested with the following compilers and tools:

Software or Resource Version Tested Description
cc 5.9 and 5.10 Sun Studio 12 C compiler
CC 5.9 and 5.10 Sun Studio 12 C++ compiler
gcc 4.1.2 and 4.2.3 GNU C compiler in Red Hat 5 and Ubuntu 8.04
g++ 4.1.2 and 4.2.3 GNU C++ compiler in Red Hat 5 and Ubuntu 8.04
gdb 6.6 and 6.8 GNU debugger in Red Hat 5 and Ubuntu 8.04
gmake 3.81 GNU make in Red Hat 5 and Ubuntu 8.04


Sun Studio 12 Compilers on Linux

If you want to use the Sun Studio 12 compilers in a Linux OS:

  • If you have Sun Studio 12 software installed, ensure that /installation directory/sunstudio12/bin is in your path before you start the NetBeans IDE. The default location is /opt/sun/sunstudio12/bin when installing with Linux packages.
  • If you do not have Sun Studio 12 software installed, you can download it from developers.sun.com as described below.

To download and install the Sun Studio 12 compilers:

  1. Create a directory where you can download and expand the Sun Studio compressed archive file. You must have write permission for this directory.
  2. If your browser is set to install in a particular location such as your Desktop or a Downloads directory without prompting, set the browser preferences to download to the directory you created. For Firefox, the download directory is set in Edit > Preferences > Main.
  3. Go to http://developers.sun.com/sunstudio/downloads/ and download the file for your platform into the download directory you created. If you are using Ubuntu, choose the tarfile installation because the packages are for SUSE and Red Hat. Note also that Ubuntu is not an officially supported platform for Sun Studio IDE, but the compilers have been tested for use in NetBeans IDE and been found to work.
  4. After the download is complete, open a terminal, go to the download directory, and uncompress and untar the downloaded file.
    bzcat filename | tar xvf -
    
  5. If you downloaded the SUSE or RPM packages, follow the instructions in Chapter 2 of the Sun Studio 12 Quick Installation (English, Japanese, Simplified Chinese) guide to install.
  6. If you downloaded the tar fil
  7. Edit your PATH to add the path to the Sun Studio software before starting the NetBeans IDE.

To download and install the GNU debugger in Red Hat 5, type:

yum install gdb

To download and install the GNU debugger in Ubuntu, type:

apt-get install gdb

Macintosh OS X

NetBeans IDE has been tested with the following compilers and tools:

Software or Resource Version Tested Description
gcc 4.0.1 GNU C compiler in Mac OS X 10.5
g++ 4.0.1 GNU C++ compiler in Mac OS X 10.5
gdb 6.3.5 GNU debugger in Mac OS X 10.5
make 3.81 GNU make in Mac OS X 10.5

Install the following packages that are provided with your Macintosh OS X:

  • Xcode
  • X11

These packages can also be downloaded from Apple Developer Connection with the free ADC membership.


Verifying the Installation

To verify that the installation is correct, start the NetBeans IDE, build a sample project, and run it in the gdb debugger.

Start the NetBeans IDE

To start the IDE, do one of the following:

  • Open the NetBeans IDE icon on the desktop.
  • In Linux or Solaris platforms, navigate to the bin subdirectory of your NetBeans installation and type ./netbeans.
  • Launch the NetBeans IDE through the desktop's menus, as you do for other applications.
    This method is available on Windows and OpenSolaris platforms, but might not be on Solaris 10 OS and some Linux platforms.

Build a Sample Project to Test the Tools

On all platforms, you can build a sample project to test the compiler installation, and run it in the debugger to test the gdb installation.

To build a sample project and run it in the debugger:

  1. Open the New Project wizard by choosing File > New Project.
  2. In the Categories panel on the Choose Project page of the wizard, expand the Samples category and select the C/C++ subcategory.
  3. In the Projects panel, select the Welcome project. Click Next.
  4. On the Project Name and Location page, click Finish.
  5. In the Projects window of the IDE, right-click the Welcome_1 project and choose Build. If your compilers and make utility are installed correctly and the path to them is set, build output is displayed in the Output window and the project builds successfully.
  6. Double-click the welcome.cc file to open it in the Source Editor.
  7. Right-click in the left margin of the Source Editor window and choose Show Line Numbers.
  8. Set a breakpoint by clicking in the left margin of the Source Editor window next to any line.
  9. Right-click the project and choose Debug. If the gdb debugger is installed correctly and the path to it is set, gdb starts up, the Debugger tabs are displayed, and the Welcome application runs and stops at the breakpoint.
  10. Choose Debug > Continue to run the application to completion.

Next Steps

To learn quickly how to develop a C or C++ application with the NetBeans IDE, see the C/C++ Projects Quick Start Tutorial

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo