Visual Studio 2010 包含文件可以“看到”但无法编译

发布于 2024-12-09 17:56:02 字数 334 浏览 0 评论 0原文

我确信有一个非常简单的解决方案。

我正在尝试包含头文件。我已经添加了包含目录。当我用引号包含时,vs2010 中的新功能现在向我显示它可以“查看”我想要包含的文件,并且工具提示在正确的目录中引用它。

但是,我在 #include 下看到一个红色下划线,表明存在问题,并且该项目将无法构建,因为它无法包含该文件。

我可以通过添加完整的相对路径来构建,但这有点混乱。

总之,

#include "myfile.h"  FAILS
#include "../../includes/myfile.h" WORKS

有什么想法吗?

I'm sure there is a really simple solution to this.

I'm trying to include a header file. I have added the include directory. when I include with quotes the new feature in vs2010 now shows me that it can 'see' the file I want to include and the tool tip references it in the correct directory.

however I get a red underscore under the #include indicating there is a problem and the project won't build because it cannot include the file.

I can build by adding the full relative path but this is a bit messy.

so in summary

#include "myfile.h"  FAILS
#include "../../includes/myfile.h" WORKS

any ideas?

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

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

发布评论

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

评论(2

懒的傷心 2024-12-16 17:56:02

您必须在以下字段中添加 ../../includes:Project

Properties > C/C++>一般>其他包含目录

有关更多详细信息,请访问相应的 MSDN 页面。

You have to add ../../includes in the following field:

Project Properties > C/C++ > General > Additional Include Directories

For more details visit the appropriate MSDN page.

凉风有信 2024-12-16 17:56:02

如果

#include "myfile.h"

失败但

#include "../../includes/myfile.h"

有效,则意味着您的路径中没有包含目录。假设您的结构如下:

/project
   /src
      myfile.cpp   -> myfile.h included here
   /include
      /dir1
          myfile.h

您需要添加到包含目录 ./include/dir1/,而不仅仅是 ./project./include< /代码>。

使用 <...> 而不是 "..." 只是告诉编译器首先查看系统包含目录,这样就不会有很大帮助。指出这一点的答案是错误的。通常,您可以将 <...> 用于 stringvector"..." 等标头code> type 包含您自己的标头。

If

#include "myfile.h"

fails, but

#include "../../includes/myfile.h"

works, that means you don't have the include directories in your path. Say you have your structure like this:

/project
   /src
      myfile.cpp   -> myfile.h included here
   /include
      /dir1
          myfile.h

You need to add to your include directories ./include/dir1/, not just ./project or ./include.

Using <...> instead of "..." just tells the compiler to first look in the system include directories first, so that wouldn't be of much help. Answers stating this are wrong. Usually, you would use <...> for headers like string or vector and "..." type includes for your own headers.

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