'GLFW not initializing on arch linux

I'm trying to build a glfw window on arch linux with gnome. But every time I try running the app it is not able to initialize the window and it just prints before init but not after init.

I build it with gcc:

gcc -o app main.c -lglfw -lGLU -lGL -lm

main.c

#include <stdio.h>
#include <GLFW/glfw3.h>

int main() {
    GLFWwindow* window;
    printf("before init\n");
    if (!glfwInit())
        return -1;
    printf("after init\n");

    window = glfwCreateWindow(800, 600, "Hello World", glfwGetPrimaryMonitor(), NULL);

    if (!window) {
        glfwTerminate();
        return -1;
    }

    glfwMakeContextCurrent(window);

    while (!glfwWindowShouldClose(window)) {
        glfwSwapBuffers(window);
        glfwPollEvents();
    }

    glfwTerminate();

    return 0;
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source