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

Time:11-11

I wanted to make a game in OpenGL and it gives me these errors so far. This doesn't make much sense, because i followed a tutorial (It was a C tutorial, but it's almost the same)

This is my code:

#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;
   }

}

These are the errors:

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

EDIT: As it turns out i had a typo. It must be GLFW_CONTEXT_VERSION_MINOR not GLFW_CONTENT_VERSION_MINOR

CodePudding user response:

If compiling as C, you must #include <stdbool.h> to get access to true, false and bool. They are only keywords in C , not in C.

  • Related