如何静态链接到现有的 rlib? [英] How to statically link to an existing rlib?
问题描述
我有两个独立创建的 libsomelibrary.rlib
文件位于 /path/to/deps/debug/
和 /path/to/deps/release/
目录.我在 /path/to/myproject/
目录中还有一个项目,它需要静态链接到 libsomelibrary.rlib
.
如何在 Cargo.toml(或其他地方)中指定对那些 .rlib 的引用?
我尝试在 Cargo.toml 中的 [dependencies]
下添加 somelibrary
.使用 build.rs 指定搜索路径和文件名:
println!("cargo:rustc-link-lib=static=somelib");println!("货物:rustc-link-search=/path/to/deps/debug/");
然后在 Cargo.toml 中:
[包]build = "build.rs"链接 = "somelibrary"
但我仍然收到链接错误.
据我所知,你得用 rustc 手动编译
rustc main.rs —-extern custom1=path/to/libcustom1.rlib —-extern custom2=path/to/libcustom2.rlib
对于 .rlib 形式的每个库,您为每个em"添加--extern".
参考这个>
还有这个>
更重要的是,rustc 的手册页将为您提供更复杂的东西,例如 FFI
I have two independently created libsomelibrary.rlib
files at /path/to/deps/debug/
and /path/to/deps/release/
directories. I also have a project in the /path/to/myproject/
directory which needs to link statically to libsomelibrary.rlib
.
How can I specify in Cargo.toml (or elsewhere) the references to those .rlibs?
I have tried to add somelibrary
under [dependencies]
in Cargo.toml. using a build.rs to specify the search path and file name:
println!("cargo:rustc-link-lib=static=somelib");
println!("cargo:rustc-link-search=/path/to/deps/debug/");
then in Cargo.toml:
[package]
build = "build.rs"
links = "somelibrary"
but I still get linkage errors.
As far as I know, you gotta manually compile with rustc
rustc main.rs —-extern custom1=path/to/libcustom1.rlib —-extern custom2=path/to/libcustom2.rlib
With every library in the form of .rlib you add ‘—-extern’ for every single one of ‘em.
Refer to this
And to this
More than that, the man page for rustc will give you extra leg on more complex things like FFI
这篇关于如何静态链接到现有的 rlib?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!