I am using Eclipse CDT v4.3.2 from the ARM DS-5 v5.20.0 package for code development and debug of a Makefile
project.
The makefile is actually a hierarchy of mkefiles that create multiple targets in multiple configurations, based on command line options.
In order to allow effective static analysis, I use the project's setting Paths and Symbols
to help the Indexer find the various include files and to highlight the right conditionally compiled code segments.
Our project contains a header file that is included in many of the modules across the code tree. However, two variants of the header file are present in two adjacent directories, for conditional use with two build configurations:
My_Project
|
+-- Include_1
| |
| +-- header.h
|
+-- Include_2
| |
| +-- header.h
|
+-- Source
| |
| +-- module_1.c
|
+-- makefile
The two variants are mostly similar, but contain some differences. These headers contain a few macro definitions and an enum
erated typedef
. Specifically, the following sample parts are identical in both variants:
// header.h
#define SYMBOL 0x1
typedef enum {
constant = 0x2
} enum_t
A typical code module includes one of these headers, depending on configuration in the makefile, and contains references to SYMBOL
and constant
.
In the paths and Symbols
tab, I added only My_Project/Include_1
to the paths list, so the indexer should not get confused. I also disabled the Allow heuristic resolution of includes
option in the Window
->Preferences
->C/C++
->Indexer
menu (in fact, I disabled all Indexer options).
With all of that, when I open the module.c
file in the editor, the references to constant
are marked with the wavy red underline, and a Symbol 'constant' could not be resolved
error is indicated. At the same time, references to SYMBOL
don't have an error indication.
When I rename one of the header files to header_x.h
then the error indication disappears.
1. Why do I get these Indexer error indications?
2. How can I eliminate them?
3. Why only the enums and not the #define-s?
Simply right click on the file > go to Resource Configurations > Reset to Default... Your header files will be found now, provided that you've written the correct include paths in your project settings.
Select C/C++ General -> Path and Symbols. Select Includes tab. In Languages list, select 'GNU C' or whatever C compiler tool chain you use. Press 'Add...' button and add the directory for the include files.
Eclipse includes a background parser called 'Indexer' which is used to assist the developer with various kind of information, for example jumping to a variable declaration or definition. Basically it is a parser running in the background collecting information about the sources and building up that 'index' data base.
Eclipse CDT indexer to my experience will index source files within the project directory whether you like it or not. There is only one way to avoid your situation: exclude them from the project, which may be done to my knowledge in two ways:
Another thing that you need to check is that you have not added accidentally the offending directory in PATH or other environment variables that may be considered by the indexer.
Apart from what is going wrong with CDT it seems that you are doing something that is not a best practice. You should put your enum in a separate header file with header guards and include that as needed.
However this is a situation that can happen and you may not have the luxury to act differently.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With