You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

NixOS Hyprland下GLFW应用libwayland-client加载失败问题解决

NixOS Hyprland环境下GLFW应用启动报错解决

问题

启动GLFW应用时抛出错误:
error: failed to initialize GLFW: Wayland: Failed to load libwayland-client

当前使用的flake.nix配置:

{
  description = "";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    zig.url = "github:mitchellh/zig-overlay";
  };
  outputs = {nixpkgs, zig, ... } @ inputs:
    let
      system = "x86_64-linux";

      pkgs = import nixpkgs {
        inherit system;
        config.allowUnfree = true;
      };

      zigMaster = zig.packages.${system}.master;
    in
      {
        devShells.${system}.default = pkgs.mkShell {
          BuildInputs = with pkgs; [
            glfw-wayland
          ];
          nativeBuildInputs = [
            zigMaster
          ];
        };
      };
}

已尝试添加wayland-protocols到BuildInputs,问题未解决。

解决方案

1. 显式添加wayland依赖

虽然glfw-wayland依赖wayland,但在mkShell环境中,有时需要显式声明才能让动态链接器正确找到libwayland-client.so。修改flake.nix中的BuildInputs:

BuildInputs = with pkgs; [
  glfw-wayland
  wayland  # 新增这一行
];

2. 验证环境变量(可选)

如果添加依赖后仍有问题,可检查LD_LIBRARY_PATH是否包含wayland库的路径:

echo $LD_LIBRARY_PATH

正常情况下mkShell会自动配置,但如果有异常,可以手动添加:

export LD_LIBRARY_PATH="${pkgs.wayland.out}/lib:$LD_LIBRARY_PATH"

3. 检查Zig的库搜索路径

Zig在构建时可能需要明确指定系统库路径,可在编译命令中添加-L${pkgs.wayland.out}/lib,或者确保Zig能识别Nix的环境变量配置。


内容的提问来源于stack exchange,提问作者VaK

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 08:17:25