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 @@ -210,6 +210,23 @@ a statically linked binary on MSVC you would execute:
210
210
RUSTFLAGS=' -C target-feature=+crt-static' cargo build --target x86_64-pc-windows-msvc
211
211
```
212
212
213
+ ## Mixed Rust and foreign codebases
214
+
215
+ If you are mixing Rust with foreign code (e.g. C, C++) and wish to make a single
216
+ binary containing both types of code, you have two approaches for the final
217
+ binary link:
218
+
219
+ * Use ` rustc ` . Pass any non-Rust libraries using ` -L <directory> ` and ` -l<library> `
220
+ rustc arguments, and/or ` #[link] ` directives in your Rust code. If you need to
221
+ link against ` .o ` files you can use ` -Clink-arg=file.o ` .
222
+ * Use your foreign linker. In this case, you first need to generate a Rust ` staticlib `
223
+ target and pass that into your foreign linker invocation. If you need to link
224
+ multiple Rust subsystems, you will need to generate a _ single_ ` staticlib `
225
+ perhaps using lots of ` extern crate ` statements to include multiple Rust ` rlib ` s.
226
+ Multiple Rust ` staticlib ` files are likely to conflict.
227
+
228
+ Passing ` rlib ` s directly into your foreign linker is currently unsupported.
229
+
213
230
[ `cfg` attribute `target_feature` option ] : conditional-compilation.md#target_feature
214
231
[ configuration option ] : conditional-compilation.md
215
232
[ procedural macros ] : procedural-macros.md
You can’t perform that action at this time.
0 commit comments