强制 Eclipse CDT 解析 #included 文件以突出显示

发布于 2025-01-02 16:31:24 字数 757 浏览 1 评论 0原文

解析 C 源代码时,Eclipse 似乎忽略了定义宏的#includes。当涉及到突出显示以及有时自动完成时,这很糟糕。作为示例,假设有以下两个头文件:

bar.h:

#define BAZ 1

foo.h:

#include "bar.h"  //<-- Jumping from here leads to the correct file

#ifdef BAZ
int baz() {       //
    return BAZ;   //  this section will be grayed out
}                 //
#else
int baz() {
    return 42;
}
#endif

int foo() {
    return baz();  // jumping from here will go to the second(42) function
}

到目前为止,我已尝试更改项目的发现选项/配置文件,并为索引器切换到“使用活动构建配置”一般偏好。 该项目是一个相对较小(但充满了宏)的 C/C++ 项目,使用外部构建器(autotools/make)。

附加说明:

我发现问题的一部分是我引用了来自不同项目的头文件,这些文件是使用 Makefile 安装到单独的目录中的。我将包含目录从已安装的目录切换到项目内部 /include 目录。现在,当我构建另一个项目时,它似乎解析了这些头文件中的宏。这并不完全漂亮,但对我来说有点用。

When parsing C sources, Eclipse seems to ignore #includes with respect to defined macros. This is bad when it comes to highlighting and also sometimes auto completion. As an example, assume the following two header files:

bar.h:

#define BAZ 1

foo.h:

#include "bar.h"  //<-- Jumping from here leads to the correct file

#ifdef BAZ
int baz() {       //
    return BAZ;   //  this section will be grayed out
}                 //
#else
int baz() {
    return 42;
}
#endif

int foo() {
    return baz();  // jumping from here will go to the second(42) function
}

So far I have tried to change the Discovery options/profile for the project as well as switching to "Use active build configuration" for the indexer in the general preferences.
The project is a relatively small (yet riddled with macros) C/C++ project using an external builder (autotools/make).

Additional Notes:

I figured out that part of the problem is that I was referencing header files from a different project that were installed to a separate directory using Makefiles. I switched the include directory from the installed, to the project internal /include directory. Now when I build the other project, it seems to resolve the macros in those header files. This is not exactly pretty, but it kind of works for me.

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

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

发布评论

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

评论(1

幸福还没到 2025-01-09 16:31:24

验证您已签入所有相关选项:

首选项-> C/C++->索引器->索引未使用的标头 (...)

Verify you have all relevant options checked in:

Preferences-> C/C++ -> Indexer -> Index unused headers (...)

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