expression
Export Rust as staticlib or cdylib
Choose staticlib when a native linker should include a Rust archive in the resulting program, or cdylib when a native consumer needs a system shared library. Both require explicit C-compatible exported symbols and ABI contracts. A shared library also needs a runtime loading/deployment policy. A static library can still require additional system libraries at final link time. The accompanying C caller is expected to print 0 1; native linking is untested.
Formal Syntax & Structure
rust syntaxrust
rustc --edition=2024 --crate-type=staticlib lib.rs; rustc --edition=2024 --crate-type=cdylib lib.rsWorking Example
Example Snippetrust
// SAFETY: the standalone fixture reserves this unique symbol.#[unsafe(no_mangle)]pub extern "C" fn bm105_classify(value: u32) -> u32 { u32::from(value > 0) }