更重要的是,rustc 的手册页将为您提供更复杂的东西,例如 FFII 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 rustcrustc main.rs —-extern custom1=path/to/libcustom1.rlib —-extern custom2=path/to/libcustom2.rlibWith every library in the form of .rlib you add ‘—-extern’ for every single one of ‘em.Refer to thisAnd to thisMore than that, the man page for rustc will give you extra leg on more complex things like FFI 这篇关于如何静态链接到现有的 rlib?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-18 13:10