corner imagecorner image
FeaturesPluginsDocs & SupportCommunityPartners

Using the C/C++ Tool Collection Descriptor - NetBeans IDE 6.5 Tutorial

Contents

Content on this page applies to NetBeans IDE 6.5

To follow this tutorial, you need the following software.

Software Version Required
NetBeans IDE (including C/C++ support) Version 6.5
Java Development Kit (JDK) Version 6 or version 5
GNU C/C++ compilers (GCC) any version

Introduction

Do you want to change compiler flags that NetBeans IDE use by default for compiling C/C++ files? Do you want to add compiler that is not supported by the NetBeans IDE? This article can help you to do this! This tutorial demonstrates how to edit existing tool collections or create a custom tool collection in NetBeans IDE 6.5.

Tool Collections

A tool collection is a set of compilers, make utility, and debugger. Every time you compile, make, or debug your code, the NetBeans IDE runs an executable file described in the tool collection descriptor. Code Assistance features use include paths and macros taken from the tool collection.

The tool collection descriptor is an xml file located in the module ${NB}/cnd2/modules/org-netbeans-modules-cnd.jar. in the folder org/netbeans/modules/cnd/resources/toolchain/.

Editing Tool Collection Descriptors

Editing a tool collection descriptor is a bit tricky since the NetBeans IDE does not provide a GUI for editing descriptors.

  1. Add the following flag in the file ${NB}/etc/netbeans.conf:
    -J-Dcnd.toolchain.personality.create_shadow=true
  2. Start the IDE, choose Tools > Options, and select C/C++ in the top pane of the Options window. The IDE creates tool collection descriptors in your user directory:
    ${userdir}/config/Services/CndToolChain/

You can edit a descriptor and the IDE will use it after you restart.

Remove the flag before you start IDE next time. It needs only once to create a shadow of bundled descriptors.

Creating a Custom Tool Collection

You can create your own tool collection. The following example creates a new NetBeans module that contains new tool collection.

  1. Create a new NetBeans module by choosing File > New Project. On the Choose Project page of the New Project wizard, select the category NetBeans Modules and the project Module at first step of the wizard. Click Next. Type the project name, for example mytoolchain and click Next.
  2. On the Name and Location page, type the code name base, for example org.myhome.mytoolchain, and select the check box Generate XML Layer. Click Finish. The IDE creates a new project.
  3. Find the file layer.xml in the Projects window. Double clicking on the file opens the file in the editor.
  4. Copy and paste the following text inside the filesystem tag:

        <folder name="Services">
            <folder name="CndToolChain">
                <file name="GNU_tuned.xml" url="toolchain/GNU_tuned.xml">
                    <attr name="position" intvalue="5000"/>
                    <attr name="extends" stringvalue="GNU"/>
                </file>
            </folder>
        </folder>
    
    This text means that the IDE will read the description of the new tool collection from file GNU_tuned.xml.

    The attribute extends means that your tool collection will extend NetBeans bundled GNU tool collection.

  5. Create the subpackage toolchain and create a new GNU_tuned.xml file in the package. Copy and paste following text:
    <?xml version="1.0" encoding="UTF-8"?>
    <toolchaindefinition xmlns="http://www.netbeans.org/ns/cnd-toolchain-definition/1">
        <toolchain name="GNU_tuned" display="GNU my tuned collection" family="GNU"/>
        <platforms stringvalue="sun_intel,lunix"/>
        <cpp>
            <compiler name="g++"/>
            <development_mode>
                <fast_build flags=""/>
                <debug flags="-g3 -gdwarf-2" default="true"/>
                <performance_debug flags="-g -O"/>
                <test_coverage flags="-g"/>
                <diagnosable_release flags="-g -O2"/>
                <release flags="-O2"/>
                <performance_release flags="-O3"/>
            </development_mode>
        </cpp>
    </toolchaindefinition>
    
    The project tree looks like the following:


  6. Run the module. Choose Tools > Options, select C/C++ from the top pane of the Options window, and select the Build Tools tab.
  7. Click Restore Default. The IDE finds the new tool collection:


  8. Create a new C/C++ sample project Welcome.
  9. Right-click the project node and choose Properties. In the Project Properties dialog box, select your GNU_tuned tool collection and build the project.
  10. Note that the compiler has flags -g3 -gdwarf-2
    g++ -c -g3 -gdwarf-2 -MMD -MP -MF build/Debug/GNU_tuned-Solaris-x86/welcome.o.d -o build/Debug/GNU_tuned-Solaris-x86/welcome.o welcome.cc
  11. In the Project Properties dialog box, select the GNU tool collection and rebuild the project.
  12. Compare the compile line:
    g++ -c -g -MMD -MP -MF build/Debug/GNU-Solaris-x86/welcome.o.d -o build/Debug/GNU-Solaris-x86/welcome.o welcome.cc

So we have managed to change compiler flags for debug, Development Mode for the GNU compiler.

More details

This is a description of most important tags in the tool collection xml file.

Tool collection definition

Tags Attributes Description
toolchain Name of tool collection
name Name of tool collection
display Display name of tool collection
family Group name of tool collection
platforms Supported platforms
stringvalue List of supported platforms separated by comma.
Possible values are:
  • linux
  • unix
  • sun_intel
  • sun_sparc
  • windows
  • mac
  • none
drive_letter_prefix Special prefix for file names
stringvalue "/" for unix
"/cygdrive/" for cygwin on Windows
base_folder Description of base folder of compilers
registry Registry key of tool
pattern Regular expression that allow to find compiler in registry
suffix Folder with executable files
path_pattern Regular expression that allow to find compiler by scanning paths
command_folder Where UNIX-like commands are located.
Actual for MinGW compiler on Windows.
registry Registry key of commands
pattern Regular expression that allow to find commands folder in registry
suffix Folder with executable files
path_pattern Regular expression that allow to find commands by scanning paths

Compiler flags

Tags Description Example for GNU compiler
c,cpp Set of compiler flags are located in following sub nodes
recognizer Regular expression that allow to find compiler For GNU under cygwin on Windows
.*[\\/].*cygwin.*[\\/]bin[\\/]?$
compiler Compiler name (name of executable file) gcc or g++
version Version flag --version
system_include_paths Flags to get system include paths -x c -E -v
system_macros Flags to get system macros -x c -E -dM
user_include Flag to add user include path -I
user_macro Flag to add user macro -D
development_mode Groups of flags for different development modes
warning_level Groups of flags for different warning level
architecture Groups of flags for different architecture
strip Flag for stripping debug information -s
dependency_generation Flags for dependency generation -MMD -MP -MF $@.d
precompiled_header Flags for precompiled header -o $@
multithreading Groups of flags for multithreading support
standard Groups of flags for different language standards
language_extension Groups of flags for different language extensions

Companion
Projects:
MySQL Database Server   GlassFish Community: an Open Source Application Server   Open Solaris  Open JDK: an Open SourceJDK   Mobile & Embedded Community     Sponsored by 
Sponsored by Sun Microsystems