Skip to content

2024

A Little C++ and CUDA with Your Rust

Refactoring

This post is under refactoring. The content is not wrong and could still help, but its future version would be better organized and more informative.

A little C with your Rust, a well-known article in The Embedded Rust Book, has briefly introduced how to call a C function from Rust without a third-party build dependency. In the post, we will step further to solve the same FFI problem in a more complex scenario: calling a C++ function that additionally contains some CUDA code from Rust without a third-party build dependency, e.g., cxx.

TL;DR - Handle name mangling and ensure using the static library - Link `libstdc++` and `libcudart` - `CUDA_RESOLVE_DEVICE_SYMBOLS ON` in addition to `CUDA_SEPARABLE_COMPILATION ON`