File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -252,6 +252,23 @@ a statically linked binary on MSVC you would execute:
252252RUSTFLAGS=' -C target-feature=+crt-static' cargo build --target x86_64-pc-windows-msvc
253253```
254254
255+ ## Mixed Rust and foreign codebases
256+
257+ If you are mixing Rust with foreign code (e.g. C, C++) and wish to make a single
258+ binary containing both types of code, you have two approaches for the final
259+ binary link:
260+
261+ * Use ` rustc ` . Pass any non-Rust libraries using ` -L <directory> ` and ` -l<library> `
262+ rustc arguments, and/or ` #[link] ` directives in your Rust code. If you need to
263+ link against ` .o ` files you can use ` -Clink-arg=file.o ` .
264+ * Use your foreign linker. In this case, you first need to generate a Rust ` staticlib `
265+ target and pass that into your foreign linker invocation. If you need to link
266+ multiple Rust subsystems, you will need to generate a _ single_ ` staticlib `
267+ perhaps using lots of ` extern crate ` statements to include multiple Rust ` rlib ` s.
268+ Multiple Rust ` staticlib ` files are likely to conflict.
269+
270+ Passing ` rlib ` s directly into your foreign linker is currently unsupported.
271+
255272[ `cfg` attribute `target_feature` option ] : conditional-compilation.md#target_feature
256273[ configuration option ] : conditional-compilation.md
257274[ procedural macros ] : procedural-macros.md
You can’t perform that action at this time.
0 commit comments