开发者

visual studio 2010 include file can 'see' but cannot compile

开发者 https://www.devze.com 2023-04-13 09:55 出处:网络
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

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 i开发者_开发问答n 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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号