How can I get Eclipse to index code inside #ifdef

2019-01-17 14:46发布

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?

6条回答
等我变得足够好
2楼-- · 2019-01-17 15:22

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

查看更多
在下西门庆
3楼-- · 2019-01-17 15:27

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

查看更多
霸刀☆藐视天下
4楼-- · 2019-01-17 15:30

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.

查看更多
Summer. ? 凉城
5楼-- · 2019-01-17 15:41

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)

查看更多
相关推荐>>
6楼-- · 2019-01-17 15:43

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.

查看更多
可以哭但决不认输i
7楼-- · 2019-01-17 15:44

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 ...

查看更多
登录 后发表回答