简体   繁体   English

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

[英]glfwInit() fails. What should I do?

So, I can't create any windows because glfwInit() fails.因此,我无法创建任何窗口,因为glfwInit()失败。

Here's my CMakeLists.txt这是我的 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.终于可以发现问题了: glfw-wayland包是在我使用X11系统的时候安装的。 Uninstalling the wayland package and installing glfw-x11 successfully resolved GLFW from being unable to initialize.卸载wayland包并安装glfw-x11成功解决了GLFW无法初始化的问题。

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.这个问题是在 5 多年前提出的,但我仍然回答,希望它可以使某人免于被封锁的日子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Istream失败。 什么是安全的使用方式! - Istream fails. What is the safe way to use it! 由IIS 7启动时glfwInit失败 - glfwInit fails when launch by IIS 7 我正在尝试对 C++ 中的两个指针的值进行算术运算,但它有时有效,有时失败。 努力在网上寻找解释 - I'm Trying to do Arithmetic on the Value of Two Pointers in C++ but it Sometimes Works and Sometimes Fails. Struggling to Find Explanations Online 如何修复错误 LNK2019:未解析的外部符号 _glfwInit - How do I fix error LNK2019: unresolved external symbol _glfwInit 如果从源代码构建 BCC 后“sudo /usr/share/bcc/tools/execsnoop”失败怎么办? - What should I do if “sudo /usr/share/bcc/tools/execsnoop” fails after build BCC from source? 尝试在类成员初始化中使用vector的fill构造函数失败。 怎么了? - Attempting to use vector's fill constructor in class member initialization fails. What is wrong? Win32文件IO工作但fopen等。 人。 失败。 这里发生了什么? - Win32 File IO works but fopen et. al. fails. What is going on here? 我应该如何处理这个奇怪的错误? - What should I do with this strange error? 未定义的引用错误,我该怎么办? - undefined reference error, what should i do? 我应该如何处理用户输入? - What should I do with the user input?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM