The .cpp program does not see the GL/glew.h file.

In the directory where the program is located (C:\2022\Work\programming\engineering\my-works\my_game\programs), there is also the glew-2.1.0 folder, which contains the include folder, which contains the GL folder, which contains header file glew.h. When I try to run the program in Visual Studio Code 1.69 (Windows 10 Home), the following text appears in the terminal:
"PS C:\2022\Work\programming\engineering\my-works\my_game\programs> cd "c:\2022\Work\programming\engineering\my-works\my_game\programs\" ; if ($?) { g++ open_gl_1_test.cpp -o open_gl_1_test } ;if
($?) { .\open_gl_1_test }
open_gl_1_test.cpp:1:10: fatal error: GL/glew.h: No such file or directory
1 | #include <GL/glew.h>
| ^~~~~~~~~~~
compilation terminated.
PS C:\2022\Work\programming\engineering\my-works\my_game\programs>".

Here is the program code itself:

#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <iostream>
using namespace std;
void init(GLFWwindow *window) {}
void display(GLFWwindow *window, double currentTime)
{
glClearColor(1.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
}
int main(void)
{
if (!glfwInit())
{
exit(EXIT_FAILURE);
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
GLFWwindow *window = glfwCreateWindow(600, 600, "Chapter2 - program1", NULL, NULL);
glfwMakeContextCurrent(window);
if (glewInit() != GLEW_OK)
{
exit(EXIT_FAILURE);
}
glfwSwapInterval(1);
init(window);
while (!glfwWindowShouldClose(window))
{
display(window, glfwGetTime());
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwDestroyWindow(window);
glfwTerminate();
exit(EXIT_SUCCESS);
}

How to ensure that the program can include the glew.h header file?
You should add something like the following to the commandline:
-IC:/path_to_folder_that/contains_the_GL_folder

You probably also need to properly add the include paths to GLFW, and link properly to both GLFW and OpenGL. But one step at a time, I guess.
Last edited on
The first line of your first OpenGL practice generates a compile error :/
I guess that you have not installed and linked what it is required in order to compile an OpenGL code. You should take a look at a simple tutorial to install properly header files and librairies. I tested your code and it works as expected with the right settings, displaying a simple window with a red background. Take a look at these links :

https://www3.ntu.edu.sg/home/ehchua/programming/opengl/HowTo_OpenGL_C.html
https://www.youtube.com/watch?v=HzFatL3WT6g

PS : please use tag when you post a code. Thanks ++
Last edited on
@Geckoo, thank you!
Topic archived. No new replies allowed.