惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Jina AI
Jina AI
N
Netflix TechBlog - Medium
P
Proofpoint News Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
DataBreaches.Net
人人都是产品经理
人人都是产品经理
aimingoo的专栏
aimingoo的专栏
Stack Overflow Blog
Stack Overflow Blog
Blog — PlanetScale
Blog — PlanetScale
月光博客
月光博客
阮一峰的网络日志
阮一峰的网络日志
I
InfoQ
F
Fortinet All Blogs
J
Java Code Geeks
Last Week in AI
Last Week in AI
美团技术团队
大猫的无限游戏
大猫的无限游戏
有赞技术团队
有赞技术团队
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园_首页
量子位
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Apple Machine Learning Research
Apple Machine Learning Research
小众软件
小众软件

The Rust Programming Language Forum - Latest posts

What's everyone working on this week (21/2026)? Rust Function Call with one Param Iced + Canvas + Text: How do I create a style for canvas text "Value dropped while borrowed" as a lifetime mismatch Weird `use of moved value` behaviour Slightly surprising behavior of a while loop Clap: how to disable options after a certain positional argument How do i tell rust-analyzer what kind of bracket to use for a macro? Iterator + Borrow Checker: Work around borrowing already borrowed mutable variable Requesting data via mavlink SKILLS.md for Rust development 🧵 Stringlet UTF-8 Hack Option Niche? Iterator + Map - How do divide every element, including the last element, by the last element Why can't we store returned value of a function in a variable if one of the parameters goes out of scope My first crate :D, floop: A more convenient and less error prone replacement for loop `{ select! { .. }}` Sorting is slow because architectures are wrong — zan-sort redesigns the architecture, not the algorithm Iced Font - Create a custom monospace font to display dollar amounts Is the UnsafePinned RFC wrong about being able to return `&mut T` from `get_mut_unchecked`? Fixing Polars 0.37 compilation errors: Hashbrown 0.17 dependency conflict and decimal parsing Any plans for improving error diagnostic in Rust 2.0? How do I build completely offline? Is `&mut T -> &mut ManuallyDrop<T>` well-defined and sound? Would you use this? — fixtura, declarative fake data injection for tests Foreign trait restrictions on native types make generics hard to use Cargo Exclude Directive Compiler reasoning around a modulo counter Multiple mutable references to elements within one vector Handling non-`Send` data in a `Send` closure Review: Static Multi Pool Allocator Rmquickjs - High-level MicroQuickJS bindings for Rust
Rustc-link-lib static library
CoreSegfault · 2026-04-19 · via The Rust Programming Language Forum - Latest posts

April 19, 2026, 9:55am 1

Hello,

I am trying to understand rustc-link-lib with a static library.

Why does this work:

println!("cargo:rustc-link-lib=sqlite3");

This file is libsqlite3.a.

What happens if I have libsqlite3.so and libsqlite3.a ?

Thank you very much in advance for any help.

this is essentially passing a -lsqlite3 flag to the linker, the behavior of which is actually linker dependent. for msvc on windows, it will look for a library file named sqlite3.lib.

for most platforms, the default behavior is to link against the static library first if it exists. if you want to ensure the static library is used, it can be explicitly specified:

println!("cargo:rustc-link-lib=static=sqlite3");

Thank you for your help.

Unfortunately this doesn't work

It says:

could not find native static library `sqlite3`, perhaps an -L flag is missing?

bjorn3 April 19, 2026, 10:55am 4

Are you sure you have a libsqlite3.a file installed on your system somewhere inside /usr?

I hope it answers your question.

This works:

println!("cargo:rustc-link-search={}", BUILD_DIR);
println!("cargo:rustc-link-lib=sqlite3");

while this doesn't:

println!("cargo:rustc-link-search={}", BUILD_DIR);
println!("cargo:rustc-link-lib=static=sqlite3");

So, by setting rustc-link-search I presume that I'm telling it where the static library should be placed. But it doesn't seem to work.

basically there are two possibilities: the library file name is wrong, or the search directory path is wrong.

for the first problem, how did you build the library? can you double check the libsqlite3.a file is a valid static library?

I would suggest you use the cc crate to build the library, if you have to build it from source yourself. a better solution would be just use the sqlite3 crate (or sqlite3-sys, or even sqlite3-src).

for the second, how did you calculated BUILD_DIR? if you build the library in the build script, you should put the artifact inside the directory as specified by cargo in the OUT_DIR environment variable. also, is BUILD_DIR a relative path or absolute path?

maybe your BUILD_DIR is wrong but the first case "happens" to work because your host system has a libsqlite3.so installed. in other words, it might seem to work but didn't do what you expected.

at last, you can always check the full linker command line by setting the --print link-args compiler flag, for example:

$ RUSTFLAGS='--print link-args' cargo build