0Pricing
C++ Academy · Lesson

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

  1. Extern C and the C ABI
  2. Calling Python from C++ via pybind11
  3. C++ for Rust FFI Boundaries
  4. Using SWIG for Multi-Language Bindings
← Back to C++ Academy