Hi,
I’m currently learning WebGPU, through this tutorial. While I was trying to set up a very basic C++ project using GLFW, I ran into the problem that no window was showing up at all.
It’s a flake project using CMake. The relevant part of flake.nix
:
nativeBuildInputs = with pkgs; [
# Development Tools
llvm.lldb
cmake
cmakeCurses
glfw-wayland
# libxkbcommon
# wayland-protocols
# extra-cmake-modules
clang-tools
llvm.clang
];
The actual C++ code:
#include <GLFW/glfw3.h>
int main() {
if (!glfwInit()) {
std::cerr << "Could NOT initialize GLFW!" << std::endl;
return 1;
}
GLFWwindow *window = glfwCreateWindow(640, 400, "WebGPU for C++", NULL, NULL);
if (!window) {
std::cerr << "Could NOT open window!" << std::endl;
glfwTerminate();
return 1;
}
glfwMakeContextCurrent(window);
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
}
glfwTerminate();
}
Relevant CMakeLists.txt
:
add_executable(App main.cpp)
set_target_properties(App PROPERTIES COMPILE_WARNING_AS_ERROR ON)
target_link_libraries(App PRIVATE glfw)
After I built the project and ran the executable, no window showed up and the execution just got stuck there forever (because of the while
loop).
I assumed it was because glfw
wasn’t compiled with the flag -DGLFW_USE_WAYLAND=ON
but I am specifically using the glfw-wayland
dependency and it automatically sets that flag here.
Am I missing some dependencies? Or did I miss something in CMakeLists.txt
? Any help would be appreciated. Thanks!