Zulan
Zulan

Reputation: 22670

Force Eclipse CDT to parse #included files for highlighting

When parsing C sources, Eclipse seems to ignore #includes with respect to defined macros. This is bad when it comes to highlighting and also sometimes auto completion. As an example, assume the following two header files:

bar.h:

#define BAZ 1

foo.h:

#include "bar.h"  //<-- Jumping from here leads to the correct file

#ifdef BAZ
int baz() {       //
    return BAZ;   //  this section will be grayed out
}                 //
#else
int baz() {
    return 42;
}
#endif

int foo() {
    return baz();  // jumping from here will go to the second(42) function
}

So far I have tried to change the Discovery options/profile for the project as well as switching to "Use active build configuration" for the indexer in the general preferences. The project is a relatively small (yet riddled with macros) C/C++ project using an external builder (autotools/make).

Additional Notes:

I figured out that part of the problem is that I was referencing header files from a different project that were installed to a separate directory using Makefiles. I switched the include directory from the installed, to the project internal /include directory. Now when I build the other project, it seems to resolve the macros in those header files. This is not exactly pretty, but it kind of works for me.

Upvotes: 3

Views: 1963

Answers (1)

Tomas Pruzina
Tomas Pruzina

Reputation: 8887

Verify you have all relevant options checked in:

Preferences-> C/C++ -> Indexer -> Index unused headers (...)

Upvotes: 1

Related Questions