Compiling a GLFW demo file without GLAD

I’m trying to compile this demo file that I found online without GLAD (just as a test). I’m using GCC on Ubuntu 20.04 and have tried these compiler options:
-lglfw3
-lglfw
-lopengl32

At first I tried to compile GLFW from scratch but couldn’t so tried installing libglfw3-dev
Right now I’m still using FreeGLUT but I prefer GLFW. Here is the code

#include <GLFW/glfw3.h>

int main(void)
{
GLFWwindow* window;

/* Initialize the library */
if (!glfwInit())
    return -1;

/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window)
{
    glfwTerminate();
    return -1;
}

/* Make the window's context current */
glfwMakeContextCurrent(window);

/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
    /* Render here */
    glClear(GL_COLOR_BUFFER_BIT);

    /* Swap front and back buffers */
    glfwSwapBuffers(window);

    /* Poll for and process events */
    glfwPollEvents();
}

glfwTerminate();
return 0;

}

-lglut worked, kinda. It compiled without saying it doesn’t exist but gives the error “glClear not found”. Thanks!

Hi @somerandompiggo,

Welcome to the GLFW forum!

You don’t need glut3 nor glut, but you will need OpenGL (not opengl32, that’s for MS Windows) and glfw3.

Check out the compilation guide for using pkg-config as this is the easiest approach: https://www.glfw.org/docs/latest/build_guide.html#build_link_pkgconfig

Since you are using OpenGL directly the compilation command would look something like:

cc $(pkg-config --cflags glfw3 gl) -o myprog myprog.c $(pkg-config --libs glfw3 gl)

Also do check out our minimal GLFW cmake starter:

Oh, thats why it looked wrong. I meant -glfw and -glfw3. Ill edit the post. Sorry