glfwInit()失败。我该怎么办?

时间:2017-04-15 21:58:16

标签: c++ opengl glfw

因此,我无法创建任何窗口,因为glfwInit()失败。

这是我的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})

我的代码:

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

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

    return 0;
}

我绝对输了。我该如何解决?

更新

添加了错误回调。它返回了这条消息:

"X11: The DISPLAY environment variable is missing"

0 个答案:

没有答案