29

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?

1
  • index so that features like 'jump to definition' and call hierarchy will work. Commented Jun 28, 2010 at 20:30

6 Answers 6

35

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)

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks so very much for this, you literally just gave me back hours of my life!
Yes, that is a solution but far from "user friendly". This is a major problem for me. It´s not practical to go around all of the code (especially for code from others) and search for all the symbols and then add them to the project properties! I don't understand why Eclipse can't have a checkbox to allow us to disable the preprocessor for indexing/reference purposes... Compared to Visual Slick (that me and my colleagues used before) this is a major disadvantage of Eclipse. (C/C++ version).
the only problem is that there may be several defines for this. i mean several...
also on eclipse website help.eclipse.org/juno/…
Note: If you use multiple build configurations and Eclipse doesn't behave as you expect, go to C/C++ General->Indexer and make sure that "Build configuration for the indexer" is set to 'Use active build configuration" if desired, or you can force it to a specific fixed configuration option.
4

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.

1 Comment

This doesn't help with conditional compiling. Code blocks in #else are still greyed out.
2

For what it's worth, getting eclipse to parse conditionally compiled code is much harder to do than would appear at first glance. I found a paper on by IBM from 2007 where they said they will prioritize for the "next release".

Handling Conditional Compilation in CDT's Core

1 Comment

thanks for that information. it was what i was looking for. basically, appart from the Spudd86 response, there is no way to get eclipse to proccess this code.
1

I had this same problem, but the code conditionally eliminated by preprocessing was perfectly valid c code and I wanted it formatted... This was my solution:

1) Global find/replace of #if to #JUNKif

2) Ctrl-Shift-F to reformat the source

3) Another global find/replace of #JUNKif to #if

Comments

0

One way to index code under flag in Eclipse(Kepler) c/c++Editor.

You can enable the compilation flags in Eclipse editor so that code under them can be indexed.

Properties > Preprocessor Include Paths > CDT User settings Entries

Click on ADD and add the Preprocessor Macro and you can specify its value.

Comments

0

Best way I guess is to use the Indexer option : Project Properties>C/C++ General>Indexer. You can choose Enable project specific settings I prefer choosing "Use active build configuration" so that all files which are actually built in the project are indexed. Anyhow you can also choose to index all files in the project even if they are not included in the build ...

1 Comment

This unfortunately doesn't solve the indexing problem of conditional compilation.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.