Eclipse/CDT 编辑器在为 ifdef 输出部分着色时不拾取项目定义的符号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2951855/
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:47:55  来源:igfitidea点击:

Eclipse/CDT editor not picking up project-defined symbols in coloring ifdef'ed out sections

eclipseeclipse-cdt

提问by Guy

The problem I'm seeing is that under preferences, C/C++ Defined symbols for different Configurations/targets aren't showing up in the code coloring.

我看到的问题是,在首选项下,不同配置/目标的 C/C++ 定义的符号没有显示在代码着色中。

When I change the active build configuration in the project menu, I would expect the editor & code coloring to pick up the symbols from the project settings, but it only seems to be picking up the symbols for one of the targets.

当我在项目菜单中更改活动构建配置时,我希望编辑器和代码着色从项目设置中选取符号,但它似乎只是选取了其中一个目标的符号。

Is there any way to have the code coloring for ifdef'ed code follow the active build configuration?

有没有办法让 ifdef 代码的代码着色遵循活动的构建配置?

回答by user443923

I solved this problem on my system by setting 'Window->Preferences->C/C++->Indexer->Use active build configuration'

我通过设置“Window->Preferences->C/C++->Indexer->Use active build configuration”在我的系统上解决了这个问题

回答by Johan

In response to phord's comment. After changing the indexer setting to "Use Active Configuration" you need to change the active conf of the project to something else and then back. Then it picks up the changes.

回应 phord 的评论。将索引器设置更改为“使用活动配置”后,您需要将项目的活动配置更改为其他内容,然后再返回。然后它接收更改。

回答by ozma

just a small addition to the symbols option: give it value 1

只是对符号选项的一个小补充:给它值 1

what worked for me is this:

对我有用的是:

  • copy the define name to clipboard(lets say we have: #ifdef DBG_TYP_1)
  • select the project in project explorer
  • go to - Project->Properties->C/C++ General->Path and Symbols
  • in the "# Symbols" tab
  • add symbolDBG_TYP_1 with value 1
  • 将定义名称复制到剪贴板(假设我们有:#ifdef DBG_TYP_1)
  • 在项目资源管理器中选择项目
  • 转到 - 项目 -> 属性 -> C/C++ 常规 -> 路径和符号
  • 在“#符号”选项卡中
  • 添加值为 1 的符号DBG_TYP_1

thanks for the tips !

感谢您的提示!

回答by Josh Kelley

Try playing around with your project's Discovery Options. (Right-click on the project, choose Properties, go under C/C++ Build, and choose Discovery Options.)

尝试使用您项目的发现选项。(右键单击该项目,选择“属性”,转到“C/C++ 构建”下,然后选择“发现选项”。)

You may need to rebuild your project after changing its build configuration in order for Eclipse to rerun its discovery, or you may need to change the discovery options for each configuration to cause them to generate different results. (Sorry, this isn't an area of the CDT that I've played much with.)

您可能需要在更改其构建配置后重新构建您的项目,以便 Eclipse 重新运行其发现,或者您可能需要更改每个配置的发现选项以使它们生成不同的结果。(抱歉,这不是我经常玩的 CDT 领域。)