如何让 Eclipse 索引 #ifdef .... #endif 中的代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3121920/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 14:51:01  来源:igfitidea点击:

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

ceclipseindexing

提问by Arthur Ulfeldt

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

我正在使用 eclipse 来处理一些 c 代码,它没有像这样在条件编译块中索引代码:

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

How can I get eclipse to index the feature_a function?

如何让 eclipse 索引 feature_a 函数?

回答by Spudd86

You could tell eclipse that USE_FEATURE_Ais 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_Ain the name feild and click OK.

你可以告诉 eclipseUSE_FEATURE_A是定义的。打开您的项目属性并转到“C/C++ 常规->路径和符号”页面,在“符号”选项卡下单击“添加”按钮并USE_FEATURE_A输入名称字段并单击“确定”。

Note: this will cause it not to index any #elsesides 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)

注意:这将导致它不会为#else你的预处理器的任何方面建立索引......所以除非它们都像有问题的那个你不能AFAIK,但如果它们是你很好。(Eclipse 包含一个 C 预处理器,用于分析您的代码上述所有内容与将 -DUSE_FEATURE_A 添加到命令行本质上相同,因此 Eclipse 的预处理器的行为将与编译器中的预处理器不同)

回答by antibus

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++/Indexerand enable "Index all header variants". Then click Project->C/C++ Indexer->rebuildand cleanand buildyour project. This should resolve all error originating from preprocessor commands.

如果有人有同样的问题(和我一样),这可以(现在?)通过转到Window->Preference->C/C++/Indexer启用“索引所有标题变体”来轻松解决。然后单击Project->C/C++ Indexer->rebuildand cleanand build你的项目。这应该解决源自预处理器命令的所有错误。

回答by craigster0

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

就其价值而言,让 eclipse 解析有条件编译的代码比乍一看要困难得多。我在 2007 年发现了 IBM 的一篇论文,他们说他们将优先考虑“下一个版本”。

Handling Conditional Compilation in CDT's Core

在 CDT 的核心中处理条件编译

回答by James Benson

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:

我有同样的问题,但是通过预处理有条件地消除的代码是完全有效的 c 代码,我希望它被格式化......这是我的解决方案:

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

1) 全局查找/替换#if 到#JUNKif

2) Ctrl-Shift-F to reformat the source

2) Ctrl-Shift-F 重新格式化源

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

3)#JUNKif 到 #if 的另一个全局查找/替换

回答by akshaypmurgod

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

在 Eclipse(Kepler) c/c++Editor 中索引标记下代码的一种方法。

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

您可以在 Eclipse 编辑器中启用编译标志,以便可以索引它们下的代码。

Properties > Preprocessor Include Paths > CDT User settings Entries

属性 > 预处理器包含路径 > CDT 用户设置条目

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

单击添加并添加预处理器宏,您可以指定其值。

回答by Binay Kumar Pradhan

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

我猜最好的方法是使用索引器选项:项目属性>C/C++ 常规>索引器。您可以选择启用项目特定设置我更喜欢选择“使用活动构建配置”,以便对项目中实际构建的所有文件进行索引。无论如何,您也可以选择索引项目中的所有文件,即使它们未包含在构建...