- rust (with cargo)
- gcc
- cbindgen
$ cd testlib
$ cargo build --release
$ cbindgen --crate testlib --lang c --output ../testlib.h
$ cp target/release/libtestlib.{so,a} ..
$ gcc example.c -L. -ltestlib -o example.out
$ gcc example.c libtestlib.a -ldl -pthread -o example.out
$ chmod +x example.out
$ LD_LIBRARY_PATH=. ./example.out
N.B. The environment variable LD_LIBRARY_PATH
is only needed for the dynamic version of the library.
The Rust (dynamic) library could also be loaded at runtime using the dlfcn.h
library.
This repository does not offer an example for this alternative.