C++ for Rust FFI Boundaries
Expose C++ functions for Rust FFI consumption and the reverse direction.
C++ and Rust
Rust and C++ are both compiled, low-level languages — but they have different ABIs and incompatible type systems. They typically interop via a C ABI bridge.
Rust to C++: extern "C"
Export Rust functions with extern "C" and #[no_mangle].
// Rust
#[no_mangle]
pub extern "C" fn add(a: i32, b: i32) -> i32 {
a + b
}All lessons in this course
- Extern C and the C ABI
- Calling Python from C++ via pybind11
- C++ for Rust FFI Boundaries
- Using SWIG for Multi-Language Bindings