遇到麻烦,包括标题文件

发布于 2025-01-28 17:10:40 字数 417 浏览 2 评论 0原文

我只能使用将其添加到C:\ sdl2-w64 \ include中的标头文件,但是我无法将其链接到项目文件夹中的Include文件夹。

例如:我有一个名为“ myproject”的文件夹,它位于c:\ users \ user \ desktop \ myproject,在项目文件夹中,有一个“ inclage”文件夹,位于\ myProject \ inclage inclate \ inclage,然后我添加一个名为“标头文件” “ head.h”到包括路径。在我的代码中,我使用#include< head.h>,然后我获得错误无法打开源文件“ head.h” ,但是如果我添加head.h c:\ sdl2-w64 \ include它的工作原理很好。

有人知道如何在我的项目文件夹中包含“包含文件夹”?

I can only use header files that I add to C:\SDL2-w64\include, but I Can't get it to link to the include folder inside my project folder.

for example: I have a folder called "MyProject" and its located at C:\Users\User\Desktop\MyProject, inside the project folder there is an "Include" folder located at \MyProject\Include then I add a header file called "head.h" to the Include path. in my code I use #include <head.h>, I then get the error cannot open source file "head.h", but if I add head.h to C:\SDL2-w64\include it works perfectly fine.

anyone know how to include the Include folder located in my project folder?

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

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

发布评论

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

评论(1

恰似旧人归 2025-02-04 17:10:40

假设执行包含的文件位于c:\ users \ user \ desktop \ myproject,请尝试使用#include“ include/head.h”。这是因为在您的包含中,使用引号(“”)和角度括号(&lt;&gt;)之间存在区别。

原因在以下答案中解释: https://stackoverflow.com/a/3162067/190999501

借助大多数编译器,#include“ blah.h”将首先在本地目录中搜索,然后从路径变量中的内容到达的内容,#include&lt; blah。 H&gt;将仅在路径中的内容中搜索。我猜想c:\ sdl2-w64 \ include在您的路径中。这可能就是为什么当您将标头文件移至该位置时,它可以找到它。

Assuming the file doing the including is located at C:\Users\User\Desktop\MyProject, try using #include "Include/head.h". This is because there is a difference between using quotations ("") and angle brackets (<>) in your includes.

The reason is explained in this answer: https://stackoverflow.com/a/3162067/19099501

But to summarize it, with most compilers, #include "blah.h" will search in the local directory first, and then the stuff it can reach from what's in your PATH variable, and #include <blah.h> will search from what's in PATH only. I am guessing that C:\SDL2-w64\include is in your PATH. That is probably why when you moved the header file to that location, it was able to find it.

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