Skip to content

Won't link when using src-build feature: cannot find -lglfw: No such file or directory #591

@Oxyd

Description

@Oxyd

Repro:

/tmp % cargo new /tmp/foo                                                
    Creating binary (application) `foo` package
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
/tmp % cd /tmp/foo 
/tmp/foo % cargo add glfw-sys -F src-build
    Updating crates.io index
      Adding glfw-sys v6.0.0 to dependencies
             Features:
             + all
             + native-egl
             + native-gl
             + native-handles
             + src-build
             + vulkan
             + wayland
             + x11
             - bindgen
             - osmesa
             - prebuilt-libs
             - static-link
    Updating crates.io index
    Blocking waiting for file lock on package cache
     Locking 5 packages to latest Rust 1.88.0 compatible versions
      Adding cc v1.2.33
      Adding cmake v0.1.54
      Adding glfw-sys v6.0.0
      Adding pkg-config v0.3.32
      Adding shlex v1.3.0 
/tmp/foo % echo 'fn main() { unsafe { glfw_sys::glfwInit(); } }' >src/main.rs
/tmp/foo % cargo build -q                                                    
error: linking with `x86_64-pc-linux-gnu-cc` failed: exit status: 1
  |
  = note:  "x86_64-pc-linux-gnu-cc" "-m64" "/tmp/rustcTqYCTr/symbols.o" "<6 object files omitted>" "-Wl,--as-needed" "-Wl,-Bstatic" "/tmp/foo/target/debug/deps/{libglfw_sys-be2787758c0f1973.rlib}.rlib" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib/{libstd-*,libpanic_unwind-*,libobject-*,libmemchr-*,libaddr2line-*,libgimli-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,libcfg_if-*,liblibc-*,liballoc-*,librustc_std_workspace_core-*,libcore-*,libcompiler_builtins-*}.rlib" "-Wl,-Bdynamic" "-lglfw" "-lX11" "-lwayland-client" "-lm" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-L" "/tmp/rustcTqYCTr/raw-dylibs" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/tmp/foo/target/debug/build/glfw-sys-732a9d06e9d2be24/out/lib" "-L" "/usr/lib64" "-L" "/usr/lib64" "-L" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/tmp/foo/target/debug/deps/foo-f00e61767f5adbd4" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: /usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../x86_64-pc-linux-gnu/bin/ld: cannot find -lglfw: No such file or directory
          collect2: error: ld returned 1 exit status
          

error: could not compile `foo` (bin "foo") due to 1 previous error

Poking around, I see that the library is actually built:

/tmp/foo % find target/debug/build/glfw-sys-732a9d06e9d2be24 -name '*.so'
/tmp/foo % find target/debug/build/glfw-sys-732a9d06e9d2be24 -name '*.a' 
target/debug/build/glfw-sys-732a9d06e9d2be24/out/lib64/libglfw3.a
target/debug/build/glfw-sys-732a9d06e9d2be24/out/build/src/libglfw3.a

However,

  1. It's in lib64 not lib where build.rs expects it to be.
  2. It's an .a, not .so, despite the static-link feature being disabled.

Versions:

% cargo --version
cargo 1.88.0 (873a06493 2025-05-10) (gentoo)
% cmake --version
cmake version 3.31.7
% x86_64-pc-linux-gnu-cc --version
x86_64-pc-linux-gnu-cc (Gentoo 14.3.0 p8) 14.3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions