[英]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.