Storing NetBeans C/C++ Projects Under Version Control Systems
Contributed by Vladimir Kvashin, maintained by Alyona Stashkova
Starting with NetBeans IDE 7.3 storing NetBeans C/C++ projects (mostly projects from existing code and projects from binary) under version control systems (VCS) became less tricky. This article covers the details of storing NetBeans C/C++ projects under VCS in NetBeans IDE.
To follow this tutorial, you need the following software.
The following issues were resolved in NetBeans IDE:
The NetBeans IDE used to change project metadata files too frequently. For example, you could just open a project that was under VCS, change nothing, and suddenly realize that some project metadata files was changed, so you needed to either check them in or roll back.
This issue was mostly related to projects from existing code and projects from binary, in other words projects that are based on user make files.
The root of the issue was due to the fact that the IDE had very little information about which files in such projects took part in build and what compiler options each file was build with. Without such knowledge, the Code Assistance feature could not be precise. So the IDE had to use some background intelligence to figure out the project content and Code Assistance configuration to parse right files with right options. Unfortunately, such intelligence stored its data in a VCS-unfriendly manner.
The compiler issue stems from the fact that compiler options used for building a project can be very specific to the machine you build your project on. For example, OpenJDK build uses
When some machine or user specific information gets into VCS, the project metadata is changed after another user checks it out and builds a project (new options are stored), although the user did no changes in the project.
For projects from existing code or from binary, you may specify the list of environment variables to be used when storing project metadata. When the IDE stores the compiler options and an option value coincides with a variable value, a macros will be written instead.
Consider the following example. There
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 build
your code with the debugging information. The best options are
In case your project is not built or does not contain any debugging information, the Configure Code Assistance wizard has a special mode, 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. For this purpose the wizard asks you to enter the path to search for headers. By default, it is a project source root.
Another thing that may alter project metadata unexpectedly are macros (
You can specify the list of such macros to ignore in the "Transient macros" field. This prevents the IDE from storing these macros values in project metadata. Macros are to be specified in the macro=value form. Here is a screenshot of a project properties:
In managed projects ("C/C++ Application", "C/C++ Dynamic Library", or "C/C++ Static Library" projects) you can also use environment variables to specify the compiler options. They should be preceded with a dollar sign and placed in curly braces as follows: