C/C++ Application How-Tos for Code Assistance
Code assistance is a set of IDE features that help you navigate and edit source code. For a C/C++ Project With Existing Sources or a C/C++ Project From Existing Binary, you can specify how your code will be parsed to enable the code assistance features of the IDE.
Note that the tips in this article mostly apply to projects from existing source or from an existing binary. For projects that are created and managed by the IDE code assistance configuration is not necessary.
If your project has a question mark in the Projects window, or an #include directive is underlined in red, then your project has unresolved include directives. The IDE uses an internal parser that is used by Code Assistance features (Code Completion, Classes window, Navigator window, etc). The markings mean that this parser cannot resolve some #include directives, because the IDE project has an incorrect configuration. This might happen if the project was created from existing sources without help from debugging information or if, for example, the source files included new libraries since the IDE project was created.
Here are some possible reasons (arranged from most to least probable):
If you hold the mouse cursor over the project folder, a tooltip displays some information about the problem. For more information, you can right-click the project and select Code Assistance -> Failed #include/#error directives.
Try launching the Configure Code Assistance wizard by right-clicking the project and choosing Code Assistance > Configure Code Assistance to resolve the problem. If you know the location of the files that correspond to the failed include directive, then you can set up the project, logical folder, and file properties manually.
Suppose your application source code is managed with a version control system (VCS) such as Mercurial, and you create an IDE project from the source code. If you open the IDE project in the IDE and pull in changes from the VCS, you should build the IDE project so it is up to date with the modifications.
After you build your project in the IDE, the project is automatically updated by the IDE in the following ways:
The IDE uses a build analyzer to gather information from the build, using an interposing technique to catch system library exec calls on Oracle Solaris and Linux platforms. By default, the build analyzer is used when you create a project with existing sources and when you manually run Configure Code Assistance. If the build analyzer is not used, the output log of the build is used to capture information.
If you do not want the IDE to perform the project updates, you can disable the build analyzer as follows:
For source code projects that set up their own environment at build time, the build analyzer might not always work well. If a build fails when the Use Build Analyzer option is selected, you should check your build script to see if you have unset the LD_LIBRARY_PATH environment variable. If LD_LIBRARY_PATH is unset, you should also unset LD_PRELOAD. When these two variables are unset, the build analyzer is automatically disabled. If you cannot modify the build script, you can disable the build analyzer as described above, and the IDE can use the output log for build information.
If you are developing a multi-platform project from existing code, you can use the same IDE project for different platforms. Create a configuration per platform and change the compiler collection, compiler options, and other project properties appropriately.
The Configure Code Assistance wizard also works on a per-configuration basis: it alters only the configuration that is currently active. So you can run it separately for each configuration and get different code assistance settings for different platforms.
The Configure Code Assistance wizard is most efficient if you built your code with debugging information (the best options are -g3 -gdwarf-2 for GNU compilers and just-g for Oracle Solaris Studio compilers.
If your project cannot be built or does not contain debugging information, the Configure Code Assistance wizard has a special mode called Search File System for C/C++ Header Files. In this mode, the NetBeans IDE tries to resolve failed include directives by searching the file system for headers. The wizard asks you to enter a path to search for headers. By default, the path searched is a project source root.
To use the wizard, right-click the project and choose Code Assistance > Configure Code Assistance. Follow the steps of the wizard to enable the IDE to update code assistance. Click the Help button to get information about each step.
Hyperlink navigation lets you jump from the invocation of a function, class, method, variable, or constant to its declaration. To use a hyperlink, do one of the following:
You can also right-click the item and select Navigate > Go to Declaration/Definition, or other options to navigate through your code.
A namespace can be defined in different files of the project. To navigate between different namespace definitions, use the Classes window (Ctrl-9). Right-click the namespace you are interested in and choose All Declarations. You will see a list of all definitions sorted by file names.