I'm using g++ on WSL Ubuntu. I cloned the GLFW repo using git, used the ccmake
command to configure and generate the binaries, then used make
inside the "build" directory to finally create the .a
file. I installed all the OpenGL-related libraries to /usr/ld
(I don't recall exactly which I installed, since I had to install so many. Regardless, the g++ command works, so I assume it was a success). Afterwards, I made a project on VS Code that looks like this:
The GLFW include-folder is from the aforementioned cloned repo, and the GLAD and KHR include-folders are from glad.dav1d.de, where I set the GL version (under API) to 3.3, and the Profile to Core.
In main.cpp
, I put a simple snippet of code meant to initialize GLFW:
#include <iostream>
#include <glad/glad.h>
#include <GLFW/glfw3.h>
int main()
{
// Initialize GLFW
if (!glfwInit()) {
std::cerr << "Failed to initialize GLFW" << std::endl;
return 1;
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
std::cout << "Success" << std::endl;
return 0;
}
Then used this to command to compile the project: g++ -Wall -I./include/ -L./lib/ src/*.{c,cpp} -lglfw3 -lGL -lX11 -lpthread -lXrandr -lXi -ldl -o main
. There were no warnings or errors or anything. After running the executable, I get the error message that GLFW failed to initialize. I was a little confused why this happened, so I typed the glxinfo
command to find out that my DISPLAY
environment variable hasn't been set.
I have absolutely no idea what this variable is, or what it's meant to represent. After scouring around on the internet, I came across export DISPLAY=:0.0
and export DISPLAY=1
and export DISPLAY=IP:0.0
, none of which worked. Any ideas on how I could resolve this?