Possible to link against C (lib*.so) (more statically)?


Hello, I am relative new to rust and wanted to ask if it is possible to link against c header files?
Currently I use XenServer extensively and wanted to rewrite some of my Python Code with rust.
There is a libxenserver, which is written in C and Contains include files, C Source Code and libxenserver.so files, is there a way to make use of this?


I assume you want to link against the library. That is possible, see https://doc.rust-lang.org/book/ffi.html .

It’s not possible to include C-header files directly (they are C-specific), but things like https://github.com/crabtw/rust-bindgen help you into generating the appropriate Rust code from C headers.


yeah linking against the library helps but the problem is, that the library is provided with a *.so file and I have no idea how to specify it. I tried with a simple Hello World library like that:

Which just outputs Hello World if called, however how could i specify where the libhello.so is ? or is this not possible since dynmaic linking will always look inside the operating system lib folder? However i thought that I could provide my program + the library inside the same folder. so that I don’t need to manage too much things.


Okai thanks I figured it out, I had trouble with a dynamically linked source file, since I would’ve needed to install it.
However I could compile a libxenserver.a file which I could manually include into my project.
After that I just need to build extern {} wrappers around the *.h files. I also needed to build a wrapper around xml2 and his init method (which I dynamically linked).

I placed the *.a file into lib/x86_64-unknown-linux-gnu folder. however I thought that it shouls somehow work for linux and mac. But I will figure that out, too.