How to call c++ dynamic library from rust?

Excuse me, I want to call C++'s dynamic library from rust. But I don’t want to build from rust.Like this,


I don’t want to compile in rust, just need to call c++ dynamic library (*.so).Because in some cases, I only need to call several functions, not all the functions need to call and use.How can I use it?

Here is my C example:
You don’t need the Command::new(“make”)… row in, only the last 2 rows.

1 Like

Thank you for your example, but this is a little different from my needs. Because of my main usage, I want to be able to call the external C++ dynamic library (*.so). But still very grateful.

I don’t think, that there is such use case covered by Rust by its own. What you need to know is to use dlfcn C interface to interoperate with so files (see: Using is directly would require much unsafe code, but I found this crate: which wraps it for you (but I never used it).

Thanks for you help!!
Maybe I need to refer to more information, still hope that someone else may use this case like me.

To link with an existing library, make the build script output search path and library name:


If the library is a standard one, also check pkg-config crate and sys crates pattern.