Writing headers for rust generated .so

can someone tell me, how to generate a .h file with .so file in my rust cdylib project

if it cannot automatically do, please tell me how to do it manually , step by step , from writing header to connecting it and running it in saple C program

my rust program takes as input

For creating C-headers from Rust.

For generating Rust-“headers” from C.

.so file is not sufficient to generate C headers.

Apart from aforementioned cbindgen, you can write a C header by hand. You need to know what functions Rust program exports (C can’t call any random Rust function, but only functions with #[no_mangle] extern annotation) and write matching prototypes in C syntax.

cbindgen failed , it says it does not know CString

yes , i want to handwrite them , ive used #[no_mangle] and extern keyword

dependency walker confirms

You can’t use CString as an argument. It’s not actually a C-compatible string. It’s a helper object for making pointers to C-compatible strings, but it’s not a string pointer itself. You have to use *const char in arguments.


how can i convert the *const char to rust string ?

See example on https://doc.rust-lang.org/std/ffi/struct.CStr.html

replacing that CString with *const char should fix problem with Cbindgen?

yeah , it did solve