GCC 编译器给我关于 true 未定义等错误

The GCC compiler gives me errors about true being undefined and more

我想用 OpenGL 制作游戏,但到目前为止它给了我这些错误。这没有多大意义,因为我遵循了一个教程(这是一个C++教程,但它几乎是一样的)

这是我的代码:

#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GL/glfw3.h>

int main(){
   glewExperimental = true;
   if(!glfwInit()){
    printf("failed to initialize GLFW\n");
    return -1;
   }
   glfwWindowHint(GLFW_SAMPLES, 4);
   glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
   glfwWindowHint(GLFW_CONTENT_VERSION_MINOR, 3);
   glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
   glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

   GLFWwindow* window;
   window = glfwCreateWindow(1024, 768, "Game", NULL, NULL);
   if(window == NULL){
    printf("Sorry to say this, but your OpenGL version must be 3.3 or above! Thanks for playing, but to continue you must update your video card drivers or if you use an old GPU you may have to replace it with a new one to play this game. I will be developing my game for OpenGL 1 and 2 soon so stay on touch.");
    glfwTerminate();
    return -1;
   }
   glfwMakeContentCurrent(window);
   glewExperimental = true;
   if(glewInit() != GLEW_OK){
    printf("Failed to initilize GLEW");
    return -1;
   }

}

这些是错误:

main.c: In function ‘main’:
main.c:7:23: error: ‘true’ undeclared (first use in this function)
    7 |    glewExperimental = true;
      |                       ^~~~
main.c:7:23: note: each undeclared identifier is reported only once for each function it appears in
main.c:14:19: error: ‘GLFW_CONTENT_VERSION_MINOR’ undeclared (first use in this function); did you mean ‘GLFW_CONTEXT_VERSION_MINOR’?
   14 |    glfwWindowHint(GLFW_CONTENT_VERSION_MINOR, 3);
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~~~
      |                   GLFW_CONTEXT_VERSION_MINOR
main.c:25:4: warning: implicit declaration of function ‘glfwMakeContentCurrent’; did you mean ‘glfwMakeContextCurrent’? [-Wimplicit-function-declaration]
   25 |    glfwMakeContentCurrent(window);
      |    ^~~~~~~~~~~~~~~~~~~~~~
      |    glfwMakeContextCurrent

编辑:事实证明我打错了字。必须是 GLFW_CONTEXT_VERSION_MINOR 而不是 GLFW_CONTENT_VERSION_MINOR

如果编译为 C,您必须 #include <stdbool.h> 才能访问 truefalsebool。它们只是 C++ 中的关键字,而不是 C 中的关键字。