如何静态链接到现有的rlib?

Las*_*zlo 6 rust

我在和目录中有两个独立创建的libsomelibrary.rlib文件。我的目录中还有一个项目需要静态链接到./path/to/deps/debug//path/to/deps/release//path/to/myproject/libsomelibrary.rlib

如何在 Cargo.toml(或其他地方)中指定对这些 .rlib 的引用?

我尝试在 Cargo.toml 中添加somelibrary以下内容[dependencies]。使用 build.rs 指定搜索路径和文件名:

println!("cargo:rustc-link-lib=static=somelib");
println!("cargo:rustc-link-search=/path/to/deps/debug/");
Run Code Online (Sandbox Code Playgroud)

然后在 Cargo.toml 中:

[package]
build = "build.rs"
links = "somelibrary"
Run Code Online (Sandbox Code Playgroud)

但我仍然遇到链接错误。

小智 3

据我所知,你必须用 rustc 手动编译

\n
rustc main.rs \xe2\x80\x94-extern custom1=path/to/libcustom1.rlib \xe2\x80\x94-extern custom2=path/to/libcustom2.rlib\n
Run Code Online (Sandbox Code Playgroud)\n

对于 .rlib 形式的每个库,您为 \xe2\x80\x98em 的每一个添加 \xe2\x80\x98\xe2\x80\x94-extern\xe2\x80\x99 。

\n

参考这个

\n

对此

\n

更重要的是,rustc 的手册页将为您提供额外的支持,帮助您处理更复杂的事情,例如 FFI

\n