Eclipse CDT 无法正确跟踪宏定义
在构建设置中,我在调试构建配置中定义了 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您必须在项目 C/C++ 索引器首选项中将选项“索引器的构建配置”设置为“使用活动构建配置”。打开项目的属性面板,转到 c/C++ General 和 Indexer,启用项目特定设置,并将底部的单选按钮更改为“使用活动构建配置”。
当然,您也可以在 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".
Of course you can also set this in the global properties panel of Eclipse to change this setting for all projects.
转到项目的属性,然后转到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.
我在 Eclipse 的每个版本中都看到过一个问题,它并不总是决定立即重建索引文件。为此,您可以开始构建(构建实际上不必完成),也可以右键单击您的项目并转到索引-> 重建。两者都会导致立即重新索引。然而,你不应该需要这个。我可以确认,简单地按照上述步骤 2 中所述更改构建配置将导致我的代码中的 #ifdef 代码检查仅在我的构建配置之一中定义的符号立即变为灰色 -熄灭或不灰显,正如它应该的那样。
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.检查提供商:-> 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.
我满意的解决方案是从 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.