I’m trying to build a simple raylib example in a nix develop shell, but I’m running into linker issues:
error: fatal linker error: unhandled relocation type R_X86_64_JUMP_SLOT at offset 0x14ada0
note: in .zig-cache/o/2025ed4b533bec04712e78af39582c95/libraylib.a(/nix/store/5m91jqg1526jzsahrgmd37k4ml3nc5l4-libx11-1.8.13/lib/libX11.so/):
Does anyone have any experience doing something similar?
files for reference:
flake.nix
{
description = "Zig development environment";
inputs = {
# Pick a reasonably recent channel; you can change this to nixos-unstable, 24.11, etc.
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
# Prebuilt Zig binaries as a flake overlay
zig-overlay.url = "github:mitchellh/zig-overlay";
# Zig language server overlay; version here should match your Zig major.minor
zls-overlay.url = "github:zigtools/zls/0.16.0";
};
outputs = {
self,
nixpkgs,
flake-utils,
zig-overlay,
zls-overlay,
...
}:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
# Expose zig-overlay as pkgs.zigpkgs
(final: prev: {
zigpkgs = zig-overlay.packages.${system};
})
];
};
# Change this to the Zig version you want that exists in zig-overlay
zigVersion = "0.16.0";
zig = pkgs.zigpkgs.${zigVersion};
# Build ZLS using that Zig
zls = zls-overlay.packages.${system}.zls.overrideAttrs (old: {
nativeBuildInputs = [ zig ];
});
raylibDeps = with pkgs; [
libGL
libX11
libXcursor
libXi
libXinerama
libXrandr
];
in
{
devShells.default = pkgs.mkShell {
packages = [
zig
zls
] ++ raylibDeps;
shellHook = ''
echo "zig $(zig version)"
echo "zls $(zls --version)"
'';
};
});
}
build.zig (extra lines compared to zig init)
const raylib_dep = b.dependency("raylib_zig", .{
.target = target,
.optimize = optimize,
});
const raylib = raylib_dep.module("raylib"); // main raylib module
const raygui = raylib_dep.module("raygui"); // raygui module
const raylib_artifact = raylib_dep.artifact("raylib"); // raylib C library
exe.root_module.linkLibrary(raylib_artifact);
exe.root_module.addImport("raylib", raylib);
exe.root_module.addImport("raygui", raygui);
Using GitHub - raylib-zig/raylib-zig: Manually tweaked, auto-generated raylib bindings for zig. https://github.com/raysan5/raylib · GitHub for the raylib bindings.