错误消息:无法打开"KHR/khrplatform.h",但程序中不存在"khrplatform"

Error message: "KHR/khrplatform.h" cannot be opened, but "khrplatform" does not exist anywhere within the program

本文关键字:khrplatform 不存在 程序 KHR 消息 错误      更新时间:2023-10-16

我正试图在OpenGL中打开一个窗口。在VisualStudio中,我用我的所有头文件(如glfw3.h和greed.h)设置了一个include目录。我的include语句格式正确:

#include <glad/glad/glad.h>
#include <GLFW/glfw3.h> 

有一个额外的"高兴/",因为在文件资源管理器中有一个多余的高兴文件夹。include文件夹中包含的另一个头文件是"khrplatform.h"。这是目录序列:

include/gree/KHR/khrplatform.h

这是我为打开窗口而写的代码:

#include <glad/glad/glad.h>
#include <GLFW/glfw3.h> 

int main() {
glfwInit(); //initializes the openGL window
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); //This line and the next set the desired version of glfw (major.minor)
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); 
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //sets openGL to the core profile (fewer functions)
return 0;
}

在我的visualstudio项目中还有一个gread.c文件,它对于窗口打开编程是必要的。我得到的错误消息将错误指定为greed.c文件中的错误。错误如下:

1>------ Build started: Project: OpenGL_SampleProject, Configuration: Debug Win32 ------
1>glad.c
1>c:usersdaviddocumentsopengllibs_includeincludegladgladglad.h(95): fatal error C1083: Cannot open include file: 'KHR/khrplatform.h': No such file or directory
1>Done building project "OpenGL_SampleProject.vcxproj" -- FAILED.

问题是文本"khrplatform.h"根本没有出现在greed.c中。所以我不知道这个bug是从哪里来的。有设置和使用OpenGL经验的人能为我回答这个问题吗?

在greed.h中,包含了khrplatform.h。使用的确切语法是:

#include <KHR/khrplatform.h>

因为您添加了另一个高兴的文件夹,所以您将包含目录设置得太高了一级。这意味着高兴.h实际上应该引用:

#include <glad/KHR/khrplatform.h>

如果你的文件夹结构是这样的:

-依赖项(在Visual Studio中设置为包含目录)

----高兴

-------高兴

----------高兴.h

-------KHR

----------khr平台.h

您必须将包含目录更改为:

-依赖

----greed(在Visual Studio中设置为include目录)

-------高兴

----------高兴.h

-------KHR

----------khr平台.h

因为这将使greed.h中的<KHR/khrplatform.h>正确。

你也可以去掉那个额外的文件夹,但如果你真的想保留它,你必须在visualstudio中更改包含目录。

您要更改的具体设置如下所示:

右键单击解决方案资源管理器中的项目名称->属性->C/C++->常规

在"附加包含目录"设置下,您必须将路径更改为上述路径。

或者,你可以更改greed.h文件,但我不建议这样做。因为你可能会在未来的某个时候更新greed,这意味着你将不得不再次手动更改那行代码。