Visual C++ Express 2010 突然不接受#includes

发布于 2024-11-08 17:13:45 字数 805 浏览 0 评论 0原文

我正在使用一个 API,它已 #define 编辑了所有包含文件。我正在使用 Visual C++ 2010 Express 进行开发,到目前为止一切正常。

我正在向项目添加一个新的 cpp 文件,但不小心添加了一个“Windows 窗体”。 VC 警告我,我的项目目前没有使用 CLR,我真的想这样做吗?我单击“否”,然后按预期添加文件。然而,在那之后,我的项目不再编译。

代码基本上如下所示:

api_header.h

#define DEFINED_HEADER_NAME "path/to/header/file.h"

stdhpf.h

#include DEFINED_HEADER_NAME

正如我所说,在很长一段时间内工作得很好。现在我明白了:

错误 C2006:'#include':需要一个文件名,找到'identifier'
致命错误 C1083:无法打开包含文件:'':没有这样的文件或目录

是什么原因导致的?我发现一些帖子说这是因为打开了预编译头,但我检查了 Project Properties >配置属性> C/C++ / 预编译头,并且它已关闭(我提到了设置路径,因为我是 VS 的新手,可能有不止一种方法可以做到这一点...)。

有什么想法吗?

I'm working with an API which has #defineed all their include files. I'm developing in Visual C++ 2010 Express, and it's been working fine up till now.

I was adding a new cpp-file to the project, and accidentally added a "Windows Form" instead. VC warned me that my project was not using CLR at the moment, did I really want to? I clicked no, and added the file as intended. After that, however, my project no longer compiles.

The code looks basically like this:

api_header.h:

#define DEFINED_HEADER_NAME "path/to/header/file.h"

stdhpf.h:

#include DEFINED_HEADER_NAME

As I said, worked fine for a long time. Now I get this:

error C2006: '#include' : expected a filename, found 'identifier'
fatal error C1083: Cannot open include file: '': No such file or directory

What is causing this? I found some post that said it was because of having turned on precompiled headers, but I checked Project properties > Configuration properties > C/C++ / Precompiled headers, and it's off (I mention the setting path since I'm new to VS, there might be more than one way to do it...).

Any ideas?

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

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

发布评论

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

评论(3

熟人话多 2024-11-15 17:13:45

几乎可以肯定,问题在于这两个语句的预处理顺序,而不是与无意中添加 Windows 窗体对象有关。

这篇知识库文章建议:

问题在于使用定义的常量在 #include 指令中指定包含文件。在宏完全展开之前正在处理指令,从而导致错误。

第二个错误似乎证实了这一点,因为它表明预处理器正在搜索名称为空的包含文件:

fatal error C1083: Cannot open include file: '': No such file or directory

The problem almost certainly lies in the order in which the two statements are pre-processed, rather than having anything to do with inadvertently adding a Windows Form object.

This knowledge base article suggests:

The problem is in using a defined constant to specify an include file in the #include directive. The directive is being processed before the macro is completely expanded, resulting in the error.

The second error seems to confirm this, as it indicates the pre-processor is searching for an include file with an empty name:

fatal error C1083: Cannot open include file: '': No such file or directory
倚栏听风 2024-11-15 17:13:45

包含文件的顺序已更改。也许 Visual Studio 在 #include "api_header.h" 之前的某个位置插入了 #include "stdhpf.h"

The order of your include files has changed. Perhaps Visual Studio inserted a #include "stdhpf.h" somewhere ahead of your #include "api_header.h".

爱冒险 2024-11-15 17:13:45

禁用预编译头。它应该有帮助。

Disable precompiled headers. It should helps.

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