Writing headers for rust generated .so


#1

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


#2

For creating C-headers from Rust.

For generating Rust-“headers” from C.


#3

.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.


#4

cbindgen failed , it says it does not know CString


#5

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

dependency walker confirms


#6

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.


#7

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


#8

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


#9

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


#10

yeah , it did solve