Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Eclipse CDT index a header file that's not in the path?

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 enumerated 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?

like image 893
ysap Avatar asked Nov 10 '15 19:11

ysap


People also ask

Could not find include file in include paths eclipse?

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.

HOW include header file in C Eclipse?

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.

What is indexer in eclipse?

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.


1 Answers

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:

  1. Select the resources, mark it derived by right clicking then properties and within resources check derived , and then rebuild the index
  2. Write an exclusive filter that excludes the resource.

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.

like image 98
g24l Avatar answered Oct 17 '22 22:10

g24l