This FAQ describes an approach to setting up viewpathed projects in Eclipse CDT. nmake projects are commonly structured in multiple build nodes using viewpathing; nmake automatically generates appropriate compilation flags to ensure source and header files are resolved according to the rules for viewpathing. However, without correct setup, the Eclipse CDT indexer will not follow the same rules, leading to incorrect header file resolution. This FAQ describes how to configure Eclipse CDT so that the CDT indexer picks up the correct files.
The approach taken here relies on configuration of CDT include paths so that correct include files are picked up by the CDT indexer. The include path settings are per file, so each source files has its own unique include path sequence, and the specific include path sequence may change depending upon the header file files included and their location in the viewpath. In this approach the CDT indexer is automatically configured from compilation lines in the build output log, so manual configuration is not necessary. However, if required include files are changed or files are moved around in the viewpath, when using this approach a rebuild may be required to update the include paths used by CDT to resolve include files.
The approach describe here has been verified in Eclipse 4.3.0M6 (Kepler)/CDT 8.2.0 and Eclipse 4.2.2 (Juno)/CDT 8.1.2 on Centos 6.4 for full project clean builds and incremental builds, and local (subdirectory) builds using the CDT "Make Targets" feature. This technique is independent of the nmake Eclipse plugin and should work whether or not the nmake Eclipse plugin has been installed.
A CDT project may be configured using the project properties screen, accessible from the main Eclipse menu via Project > Properties > C/C++ General > Preprocessor Include Paths, Macros etc.. In the Entries tab, select GNU C, then CDT GCC Build Output Parser and check Enable language settings providers for this project. Configuration will apply to the project currently selected in the Project Explorer.
In the Providers tab, make sure that CDT GCC Build Output Parser is checked, and select it to configure the build output parser provider. A Language Settings Provider Options screen should appear as shown in the screenshot below.
Key settings are:
+symbol followed by a space, so this prefix must be specified in the pattern. The rest of the pattern must match the compilation commands as found in the project build log. See the above screen shot for an example.
-I-support to work. Otherwise, the
-include path may get modified and
-I-processing will not occur. This option may not be visible for some default screen sizes, it may be necessary to expand the dialog window to expose this option setting.
A couple other standard build settings must be correctly configured
for viewpathing to work. In Project > C/C++ Build on the
Builder Settings tab, make sure that Build Directory is set to the
the top node where the project build starts off. In Project >
C/C++ Build > Environment, add a
VPATH variable specfying the
build time viewpath to be passed to nmake during a build.
also be set to include the directory where the nmake executable
With these settings in effect, after running a build, the CDT build output scanner will set correct include paths on each source file in the build. The icons for source files that are currently configured this way will show a small wrench decorating their icon in the Project Explorer. The include paths for a source file may be viewed in the file properties. Right click the source file in the Project Explorer and select Properties. Then in the properties screen, select C/C++ General > Preprocessor Include Paths, Macros etc., then under Setting Entries expand CDT GCC Build Output Parser to display a list of discovered include paths and symbols for that source file. A typical display is shown in the following screen shot:
Here we are displaying properties for source file
hw.c. There are 3
entries in the include path list, the third entry is a
the location of a
-I- flag on the compilation line generated by nmake.
With this configuration, the CDT indexer will obey
-I- semantics so
that header files in directories list before the
- entry will be
used in preference to header files in the directory of the source file
for header files included using the
It may be desirable to disable one or more of the CODAN Code Analysis checkers due to the number of false positives generated in large viewpathed projects (perhaps due to code duplication), especially if all viewpath nodes are brought into the project as described in the next section. CODAN settings are found at Project > Properties > C/C++ General > Code Analysis.
There remains a question of how to structure viewpathed projects in Eclipse. One approach is to locate the roots of all project build nodes in the viewpath under the Eclipse project root. A view of an example project following this approach in Project Explorer is shown is the following screenshot:
View of example viewpathed project in Project Explorer
The name of the project is vptest5 which appears as the root element
in the display. Under vptest5, the root directories of three viewpath
nodes appear as siblings with names
the top viewpath node and is partially expanded to show a typical
nmake build structure.
The top node
src directory is highlighted, builds will typically run
from within this source area in the top node.
The bottom node
vp3 will typically contain a complete
baseline source set where source files are set read only.
Including all vpath nodes in the project has the advantage that all sources in the build will be part of the project, allowing navigation through the Project Explorer and inclusion in the CDT Index.
Typically, project build nodes do not exist as siblings in the file system. However, viewpath nodes can be made to appear as siblings through symlinks to the actual viewpath node root directories. The build viewpath is then configured to use the symlinked node locations.