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

推荐订阅源

WordPress大学
WordPress大学
博客园 - 司徒正美
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
A
About on SuperTechFans
Google DeepMind News
Google DeepMind News
T
Tailwind CSS Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
M
MIT News - Artificial intelligence
L
LangChain Blog
aimingoo的专栏
aimingoo的专栏
Engineering at Meta
Engineering at Meta
Martin Fowler
Martin Fowler
H
Help Net Security
B
Blog
Y
Y Combinator Blog
小众软件
小众软件
S
SegmentFault 最新的问题
I
InfoQ
爱范儿
爱范儿
Hugging Face - Blog
Hugging Face - Blog
D
Docker
博客园 - 【当耐特】
J
Java Code Geeks
阮一峰的网络日志
阮一峰的网络日志

The Rust Programming Language Forum - Latest topics

Beginner building a Rust backend framework (AI-assisted) — feedback appreciated C++ to Rust -- Exceptions Re-exporting a trait with a custom derive_macro Gold linker is deprecated Why is using PhantomData valid in this case? Code review for Static Pool Allocator Looking for a pool based allocator Why is this legal? What does it mean for Rustc to run "out of TLS keys"? Using async/await internally with no internal runtime, but exposing a nonblocking poll API — is this a reasonable design? Testing functions that use randomness `cargo-path`: improve coding agents&#39; ability to find Rust documentation Rust task runners Lifetime weird case Windows - USB device not detected A random rustc-ice-[...].txt file appeared Develop rust where the environment is setup in a docker Undefined Behavior: in-bounds pointer arithmetic failed: attempting to offset pointer by 20 bytes, but got alloc238 which is only 1 byte from the end of the allocation Unbug 0.5 - Runtime debug assertions Is there a tiny error in section 6.2 Reference types? Lifetime woes implementing ratatui::Widget for a reference Rusqlite + Chrono: How do I simplify code to obtain chrono datetime value From OOP to Rust – struggling with code organization and data structure design Way to avoid a self-referential struct Rust RF and audio resources/communities Whyhttp - HTTP mocks that fail where the bug actually is Using tokio channel permits in a tower service Arc::increment_strong_count design question (cross-post) `&T`, `&mut T`, `Pin<&mut T>` and `&Cell<T>`: Ways of Borrowing a `T` Ratatui detect arrow key press and release
Rustc-link-lib static library
CoreSegfault · 2026-04-19 · via The Rust Programming Language Forum - Latest topics

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