user1496491
user1496491

Reputation: 583

glfwInit() fails. What should I do?

So, I can't create any windows because glfwInit() fails.

Here's my CMakeLists.txt

cmake_minimum_required(VERSION 3.7)
project(DuperTest)

set(CMAKE_CXX_STANDARD 14)

set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
add_subdirectory(glfw-3.2.1)

set(SOURCE_FILES main.cpp)
add_executable(DuperTest ${SOURCE_FILES})

find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIRS})

target_link_libraries(DuperTest glfw)
target_link_libraries(DuperTest ${OPENGL_LIBRARIES})

And my code:

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

int main()
{
    if (!glfwInit())
    {
        std::cout << "glfwInit" << std::endl;
        glfwTerminate();
        return -1;
    }

    return 0;
}

And I'm absolutely lost. How do I fix it?

UPDATE:

added error callback. It returned this message:

"X11: The DISPLAY environment variable is missing"

Upvotes: 2

Views: 6921

Answers (1)

BenR
BenR

Reputation: 2936

I had this issue for days and was unable to find anything helpful online. I was finally able to discover the problem: The glfw-wayland package installed while I was using the X11 system. Uninstalling the wayland package and installing glfw-x11 successfully resolved GLFW from being unable to initialize.

The question was asked over half a decade ago, but I still answer in the hopes that it might save somebody from days of being blocked.

Upvotes: 2

Related Questions