Description
I modified the llama.cpp repo that llama-cpp-2 has as a submodule to expose a new symbol & then added a method to call that new symbol in llama-cpp-2 via a Rust pub API. I then called the new Rust pub API in my code and added cpal as a dependency and the path to my local llama-cpp-2 as a dependency with the cuda feature on (cuda doesn't matter but right now that forces llama.cpp to be built as a shared library). I then tried to build my crate. I also installed libllama.so in my OS.
I expected to see this happen: Crate builds
Instead, this happened: Crate fails to link saying the new symbol I added to llama.cpp is missing.
The root cause is that cpal depends indirectly on alsa-sys which uses pkg-config which adds the location of the found library to the search path. This happens before llama-cpp-2 runs and thus the linker things it should use the OS dynamic library that doesn't have the symbol & fails. While there's no way to specify priority and while valuable, that feels like it would be a much larger discussion.
I was wondering if a more targeted fix would be to ensure that all paths under OUT_DIR are moved to the front (in an order-preserving way) while the remaining directories are moved later (in an order-preserving way). That way the linker ALWAYS looks for paths within OUT_DIR before looking in other locations.
I'm not sure if this bug is in rust itself or in Cargo. Now that I think about it I'll cross-file into Cargo and link these two bugs together (15220).
Meta
rustc --version --verbose
:
rustc --version --verbose
rustc 1.84.0 (9fc6b4312 2025-01-07)
binary: rustc
commit-hash: 9fc6b43126469e3858e2fe86cafb4f0fd5068869
commit-date: 2025-01-07
host: x86_64-unknown-linux-gnu
release: 1.84.0
LLVM version: 19.1.5