Rust "could not find native static library" at Link Time in CI
rustc was told to link a native static library (via #[link] or a build script) but couldn’t find the .a file on any library search path. The static library isn’t installed, or the -L search path is wrong.
What this error means
The link step fails with could not find native static library X, perhaps an -L flag is missing?. Unlike a missing dynamic -lX, here a static archive is required and absent - common when a crate requests static linking.
error: could not find native static library `sqlite3`, perhaps an -L flag is
missing?
error: could not compile `app` (bin "app") due to 1 previous errorCommon causes
The static library isn’t installed
Static linking needs the .a archive (e.g. libsqlite3.a), which often ships separately from the shared .so. Many images include only the dynamic library.
Library present but not on the search path
The .a exists in a non-standard prefix that rustc’s link search doesn’t include, so the linker can’t find it without an added -L path.
How to fix it
Install the static library
Add the package that provides the .a archive, or build the dependency with a vendored/static feature.
# Debian/Ubuntu often needs a -dev or static package
apt-get update && apt-get install -y libsqlite3-dev
# some distros split static libs out (e.g. *-static on Alpine)
apk add --no-cache sqlite-staticAdd the library search path
If the archive lives elsewhere, point rustc at it with an -L flag via RUSTFLAGS or a build script.
export RUSTFLAGS="-L native=/opt/lib"
cargo build --lockedHow to prevent it
- Install static archives (
.a) when a crate links statically, not just the shared libs. - Use
bundled/vendoredcrate features to avoid system static-lib dependencies. - Set
-L native=...for libraries in non-standard prefixes.