glfwInit unintentionally using wayland

So I’m trying to get GLFW to work with the simplest code possible:

#include
#include <GLFW/glfw3.h>

using namespace std;

void error_callback(int error, const char* description)
{
fprintf(stderr, “Error: ‘%s’\n”, description);
}

int main() {
glfwSetErrorCallback(error_callback);

if (!glfwInit()) {
    std::cout << "Error: glfwInit" << std::endl;
}
else {
    std::cout << "Succes: glfwInit" << std::endl;
}
return 0;

}

Sadly, running this code returns the following error:

Error: ‘Wayland: Failed to connect to display’

This seems weird, because I am not using wayland.

echo $XDG_SESSION_TYPE

gives me x11, so i would expect glfwInit() to use that, instead of wayland. Does anyone know how to fix this problem? I am using ubuntu 18.04.

Hi Zeepaardje98 welcome to the forum!

How did you get/compilethe GLFW library? It sounds like it might be compiled with Wayland support but not X11.

I think you’re right. I’m not sure how I compiled it with wayland support, but remaking the files seem to have fixed the problem. Thanks for your time!