Can't Link Custom Static Libraries #1766
-
|
So the project I am trying to cross-compile uses a client socket to communicate with another program on my Raspberry Pi. The Rust socket functions didn't work as well on the Pi as they did on my desktop, so I'm going to use a C++ socket instead. I compiled that into a .a static library, saved it in ./lib, tested with cargo run, it worked perfectly. When I went to cross-compile it for the Pi, I recompiled the static library for aarch64 successfully but when I tried cross build, I got this: The static library was recompiled for aarch64, it's in the same lib folder, the title should be correct (libaibusclient.a), why doesn't cross seem to be seeing it? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 10 replies
-
|
The issue is likely that The most reliable fix is using a // build.rs
fn main() {
let dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
println!("cargo:rustc-link-search=native={}/lib", dir);
println!("cargo:rustc-link-lib=static=your_lib_name");
// You likely need to link the C++ runtime explicitly as well
println!("cargo:rustc-link-lib=stdc++");
}One gotcha to watch out for: ensure your static library follows the |
Beta Was this translation helpful? Give feedback.

That's the issue - the symlink. When
crossmounts your project into Docker at/project, it copies the symlink itself but the target it points to doesn't exist inside the container. So the linker sees a broken symlink and can't find the.afile.The fix: replace the symlink with the actual file. Either copy it directly:
Or if you want to keep building the lib separately and having it auto-update, add a pre-build step to your workflow that dereferences the symlink before running
cross: