c语言 - 如何修复此特定"undeclared identifier"错误?



我正在尝试学习如何使用高兴和glfw在c中制作游戏和模拟。尝试将任何函数中的结构体Window用作参数或仅声明Window实例时发生此错误。我收到'Window': undeclared identifier错误。通过研究stackoverflow上的错误,我明白这可能意味着我有一个循环include(我似乎不知道在哪里(。(我对c还很陌生,所以我很感激任何帮助(


核心。h:

#ifndef MINECRAFTCLONE_CORE_H
#define MINECRAFTCLONE_CORE_H
#include <stdio.h>
#include <glad/glad.h>
#include <GLFW/glfw3.h>
extern int error(char* error);
#endif

核心.c:

#include "Core.h"
int error(char* error)
{
printf("%s", error);
return -1;
}

窗口.h:

#ifndef CORE_WINDOW_H
#define CORE_WINDOW_H
#include "Core.h"
struct Window
{
int width;
int height;
char* title;
GLFWwindow* res;
};
extern int coreCreateWindow(struct Window* window,
int width, int height, char* title);
extern int coreLoopWindow(struct Window* window);
#endif

窗口.c:

#include "Core.h"
#include "Window.h"
int coreCreateWindow(struct Window* window,
int width, int height, char* title)
{
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
if (!glfwInit())
return error((char*)"Failed to initialize glfw");
window->width = width;
window->height = height;
window->title = title;
window->res = glfwCreateWindow(window->width, window->height,
window->title, 0, 0);
if (!window->res)
return error((char*)"Failed to create glfw window");
glfwMakeContextCurrent(window->res);
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
return error((char*)"Failed to initialize glad");
return 0;
}
int coreLoopWindow(struct Window* window)
{
while (!glfwWindowShouldClose(window->res))
{
glfwPollEvents();
}
glfwDestroyWindow(window->res);
glfwTerminate();
return 0;
}

main.c:

#include "Core.h"
#include "Window.h"

int main()
{
Window* window;
return 0;
}

您还没有定义一个名为Window的类型,用它可以定义一个类似的变量

Window *window;

已经定义了一个struct Window,用它可以像一样在main()中定义window变量

struct Window *window;

以同样的方式,您已经定义了所有函数原型的window参数。

最新更新