Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get Eclipse to index code inside #ifdef .... #endif

I'm using eclipse to work on some c code and it is not indexing code inside conditional compilation blocks like this:

#ifdef USE_FEATURE_A
int feature_a(...) {
   some = code(here);
}
#endif

How can I get eclipse to index the feature_a function?

like image 798
Arthur Ulfeldt Avatar asked Jun 25 '10 22:06

Arthur Ulfeldt


People also ask

How do I index a project in Eclipse?

The following has worked for me in Eclipse Neon: New Project -> C/C++ -> Makefile project with existing code -> Next. Then Navigate to the code and finish the project creation. Indexing starts automatically.


2 Answers

You could tell eclipse that USE_FEATURE_A is defined. Open your project properties and go to the "C/C++ General->Paths and Symbols" page, under the "Symbols" tab click the "Add" button and put USE_FEATURE_A in the name feild and click OK.

Note: this will cause it not to index any #else sides to your preprocessor stuff... so unless they are all like the one in question you can't AFAIK, but if they are they you're good. (Eclipse contains a C preprocessor that it uses to analyize your code all the stuff above does is essentially the same as adding -DUSE_FEATURE_A to your command line so Eclipse's preprocessor will behave differently from the one in your compiler)

like image 77
Spudd86 Avatar answered Oct 17 '22 03:10

Spudd86


This is an easier and in my opinion more elegant solution to the one selected as the solution:

If someone has the same problem (as I had), this can (now?) easily be solved by going to Window->Preference->C/C++/Indexer and enable "Index all header variants". Then click Project->C/C++ Indexer->rebuild and clean and build your project. This should resolve all error originating from preprocessor commands.

like image 4
antibus Avatar answered Oct 17 '22 01:10

antibus