简体   繁体   中英

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"

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM