C++ Visual Studio 不能包含头文件。
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12561048/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Visual Studio cannot include header file.
提问by Itchy Nekotorych
Visual studio projects have a folder for header files. So, I put the header file in there thinking I would be able to type #include "SDL.h", but that didn't work. I did some searching for it and found nothing helpful.
Visual Studio 项目有一个用于存放头文件的文件夹。所以,我把头文件放在那里,认为我可以输入 #include "SDL.h",但这没有用。我做了一些搜索,但没有发现任何帮助。
回答by Luchian Grigore
Putting the header there only helps organize your files, it doesn't copy the file to the include directories nor makes it automatically visible.
将标题放在那里只会帮助组织您的文件,它不会将文件复制到包含目录,也不会使其自动可见。
You'll need to add the path to where SDL.h
is located to your project additional include directories.
您需要将所在SDL.h
位置的路径添加到您的项目附加包含目录中。
Just right-click on the project -> Configuration Properties -> C/C++ -> General -> Additional Include Directories.
只需右键单击项目 -> 配置属性 -> C/C++ -> 常规 -> 附加包含目录。
In fact, you shouldn't have to add SDL.h
to the solution, having the path in the Additional Include Directories is enough.
事实上,您不应该添加SDL.h
到解决方案中,在附加包含目录中拥有路径就足够了。
回答by Fszczemton
This folder view that you can see on the left is just project organisation hierarchy - it does not reflect your disk hierarchy and the actual location on the disk of your file can be totally different. And #include takes into account your disk location (and all the search paths set in the project properties)
您可以在左侧看到的这个文件夹视图只是项目组织层次结构 - 它不反映您的磁盘层次结构,并且文件在磁盘上的实际位置可能完全不同。并且 #include 考虑到您的磁盘位置(以及在项目属性中设置的所有搜索路径)
So, to make short: - Check if your SDL.h file is in a reachable location on disk :)
因此,简而言之:-检查您的 SDL.h 文件是否位于磁盘上可访问的位置:)