Visual Studio 2010 包含文件可以“看到”但无法编译
我确信有一个非常简单的解决方案。
我正在尝试包含头文件。我已经添加了包含目录。当我用引号包含时,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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须在以下字段中添加
../../includes
:ProjectProperties > 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.
如果
失败但
有效,则意味着您的路径中没有包含目录。假设您的结构如下:
您需要添加到包含目录
./include/dir1/
,而不仅仅是./project
或./include< /代码>。
使用
<...>
而不是"..."
只是告诉编译器首先查看系统包含目录,这样就不会有很大帮助。指出这一点的答案是错误的。通常,您可以将<...>
用于string
或vector
和"..."
等标头code> type 包含您自己的标头。If
fails, but
works, that means you don't have the include directories in your path. Say you have your structure like this:
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 likestring
orvector
and"..."
type includes for your own headers.