如何让Eclipse在#ifdef…#endif中索引代码

时间:2022-02-13 08:04:21

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函数?

6 个解决方案

#1


27  

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.

您可以告诉eclipse USE_FEATURE_A已经定义。打开你的项目属性,进入“C/C+ General->路径和符号”页面,在“符号”选项卡下点击“添加”按钮,将USE_FEATURE_A放在feild中,点击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)

注意:这将导致你的预处理器没有任何其他的索引。所以,除非他们都像你所讨论的那个人,否则你不能接受,但如果他们是,你就是好人。(Eclipse包含一个C预处理器,它用来分析你的代码,上面所做的工作基本上与在命令行中添加-DUSE_FEATURE_A相同,所以Eclipse的预处理器与编译器中的预处理器会有不同的表现)

#2


1  

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解析有条件编译的代码比第一眼看到的要困难得多。我找到了IBM 2007年的一篇论文,他们说他们将优先考虑“下一个版本”。

Handling Conditional Compilation in CDT's Core

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

#3


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:

我也有同样的问题,但是预处理有条件地排除的代码是完全有效的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

#4


1  

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.

如果有人有同样的问题(就像我一样),这可以(现在?)通过窗口->偏好->C/ c++ /Indexer和启用“索引所有头变量”轻松解决。然后点击项目->C/ c++ Indexer->重建和清洁并建立你的项目。这将解决来自预处理器命令的所有错误。

#5


0  

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

在Eclipse(Kepler) c/c++编辑器中标记代码的一种方法。

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 ADD and add the Preprocessor Macro and you can specify its value.

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

#6


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

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

#1


27  

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.

您可以告诉eclipse USE_FEATURE_A已经定义。打开你的项目属性,进入“C/C+ General->路径和符号”页面,在“符号”选项卡下点击“添加”按钮,将USE_FEATURE_A放在feild中,点击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)

注意:这将导致你的预处理器没有任何其他的索引。所以,除非他们都像你所讨论的那个人,否则你不能接受,但如果他们是,你就是好人。(Eclipse包含一个C预处理器,它用来分析你的代码,上面所做的工作基本上与在命令行中添加-DUSE_FEATURE_A相同,所以Eclipse的预处理器与编译器中的预处理器会有不同的表现)

#2


1  

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解析有条件编译的代码比第一眼看到的要困难得多。我找到了IBM 2007年的一篇论文,他们说他们将优先考虑“下一个版本”。

Handling Conditional Compilation in CDT's Core

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

#3


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:

我也有同样的问题,但是预处理有条件地排除的代码是完全有效的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

#4


1  

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.

如果有人有同样的问题(就像我一样),这可以(现在?)通过窗口->偏好->C/ c++ /Indexer和启用“索引所有头变量”轻松解决。然后点击项目->C/ c++ Indexer->重建和清洁并建立你的项目。这将解决来自预处理器命令的所有错误。

#5


0  

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

在Eclipse(Kepler) c/c++编辑器中标记代码的一种方法。

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 ADD and add the Preprocessor Macro and you can specify its value.

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

#6


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

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