Embedding Rust in C/C++
summary
Concrete recipes for embedding Rust inside existing C/C++ code appear: use extern "C" and no_mangle to expose symbols, add crate-type like cdy lib or staticlib, generate headers with the mentioned sea pines gem, and run cargo then your C/C++ linker. Memory uses Box and Box::into_raw so C holds pointers; errors map to Result-like structs or C double-pointer patterns. A C shim can call into Rust and a small C shim plus careful linking makes throwing C++ exceptions from Rust work but depends on compiling with a C++ toolchain.
AI-written summary · about
chapters (5)
- 0:00Start
- 3:20Application Binary Interface
- 13:13BUILD SYSTEM SUPPORT
- 13:50MEMORY MANAGEMENT
- 16:37COMMUNICATING ERRORS
related talks
25mRust and C++
53mC++/Rust Interop: A Practical Guide to Bridging the Gap Between C++ and Rust
31mUsing Rust from C... or Any Language
01h 29mA Friendly Introduction to Rust for C++ Developers
36mUsing Rust with Ruby
08mLightning Talk: C++ and Rust Bindings - Mixing It Best With CMake
35mÀ la carte: mix and match C, Rust and Go!
41mWe can have nice things
