Eclipse CDT 无法正确跟踪宏定义

发布于 2024-10-21 13:30:23 字数 280 浏览 5 评论 0原文

在构建设置中,我在调试构建配置中定义了 DEBUG,这样我就可以让我的代码根据构建类型执行单独的操作。

然而,在 Eclipse 中,它会使预处理器排除的代码部分变暗,并且当我更改设置时(无论我当前正在构建调试还是发布),这不会跟上。因此,我有一堆永远变暗的代码,并且 Eclipse 索引器和其他有用的功能在这些区域内不起作用。

如何修复?还有其他人遇到过这种情况吗?

更新:仍然有这个问题。我最终放弃了单元测试构建配置,只是将该功能放入命令行开关中。这样我就可以在编写单元测试时使索引正常工作。

In the build settings I have it define DEBUG when in the debug build configuration, so that I may make my code do separate things depending on which type of build it is.

However in Eclipse it darkens out the parts of the code which are excluded by the preprocessor, and this doesn't keep up when I change the setting (whether I'm currently building debug or release). So, I have a bunch of code which is perpetually darkened out, and the Eclipse indexer and other helpful features don't work inside of those areas.

How to fix? Has anyone else encountered this?

Update: Still having this issue. I eventually abandoned my unit-test build configs and simply put that functionality into a command-line switch. Just so that I could get indexing to work while I write my unit tests.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

春花秋月 2024-10-28 13:30:23

您必须在项目 C/C++ 索引器首选项中将选项“索引器的构建配置”设置为“使用活动构建配置”。打开项目的属性面板,转到 c/C++ General 和 Indexer,启用项目特定设置,并将底部的单选按钮更改为“使用活动构建配置”。

CDT 索引器设置

当然,您也可以在 Eclipse 的全局属性面板中进行设置,以更改所有项目的此设置。

You have to set the option "Build configuration for the indexer" to "Use active build configuration" in the projects C/C++ indexer preferences. Open the properties panel for the project, go to c/C++ General and Indexer and enable project specific settings and change the radiobutton on the bottom to "Use Active build configuration".

CDT indexer settings

Of course you can also set this in the global properties panel of Eclipse to change this setting for all projects.

我的鱼塘能养鲲 2024-10-28 13:30:23

转到项目的属性,然后转到C/C++ 常规 -> 路径和符号 -> 符号。在那里添加您的定义,它就会起作用。

Go to your project's Properties, then go to C/C++ General -> Paths and Symbols -> Symbols. Add your defines there and it will work.

趁年轻赶紧闹 2024-10-28 13:30:23
  1. 如果您想根据构建配置更改系统的定义,则需要正如 dgrant 所说:“Project属性并选择C/C++ General -> Paths and Symbols,然后选择Symbols选项卡”,但您需要确保您拥有在窗口顶部选择正确的配置。另外,请确保将符号添加到列表中时不要选中“添加到所有配置”复选框。
  2. 如果您希望编辑器中的 CDT 解析正确的符号集,您还需要确保正确的构建配置也处于活动状态。为此,右键单击您的项目并选择构建配置 -> 设置为活动 ->并选择您想要激活的构建配置。 CDT 现在将解析所有文件,就好像此构建配置处于活动状态一样,使用您在上一步中定义的全局符号。

我在 Eclipse 的每个版本中都看到过一个问题,它并不总是决定立即重建索引文件。为此,您可以开始构建(构建实际上不必完成),也可以右键单击您的项目并转到索引-> 重建。两者都会导致立即重新索引。然而,你不应该需要这个。我可以确认,简单地按照上述步骤 2 中所述更改构建配置将导致我的代码中的 #ifdef 代码检查仅在我的构建配置之一中定义的符号立即变为灰色 -熄灭或不灰显,正如它应该的那样。

  1. If you want to change the defines for your system based on build configuration, you need to do as dgrant said here: "Project properties and select C/C++ General -> Paths and Symbols then select the Symbols tab", but you need to make sure you have the correct configuration selected at the top of your window. Also be sure when you add the symbol to the list that you DON'T check the "add to all configurations" checkbox.
  2. If you want your correct set of symbols to be parsed by CDT in your editor, you'll also need to make sure you have the correct build configuration active as well. To do that, right-click on your project and select Build Configurations -> Set Active -> and select the build configuration you want to make active. CDT will now parse all the files as if this build configuration were active instead, using the global symbols you defined in the last step.

There is a problem I've seen with every version of Eclipse where it doesn't always decide to rebuild your index files immediately. To get it to do so, you can either start a build (the build doesn't actually have to complete), or you can right-click on your project and go to Index -> Rebuild. Both cause an immediate re-indexing to occur. You shouldn't need this, however. I can confirm that simply changing the build configuration as described in step 2 above will cause an #ifdef I have in my code which checks for a symbol defined only in one of my build configurations to immediately become greyed-out or un-greyed-out, as it should.

你的背包 2024-10-28 13:30:23

检查提供商:-> C/C++ 通用 ->预处理器包括路径、宏等->供应商-> CDT 管理的构建设置条目。应该启用它。

检查定义的符号是否在此提供程序的条目中。

索引器是可选的。

Check provider: -> C/C++ General -> Preprocessor Include Paths, Macros etc. -> Providers -> CDT Managed Build Settings Entries. It should be enabled.

Check if defined symbol is in entries of this provider.

Indexer is optional.

小瓶盖 2024-10-28 13:30:23

我满意的解决方案是从 Eclipse 转向使用可用的 libclang 插件的编辑器:Sublime Text、Vim。

对于 C/C++ 的智能 IDE,XCode 或 MSVC 可能不会出错。

My satisfactory solution has been to move away from Eclipse to editors with a working libclang plugin: Sublime Text, Vim.

For an intelligent IDE for C/C++, one probably can't go wrong with XCode or MSVC.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文