From 7e9270f8f8d5e30c349d6e6c47a029f3002c8586 Mon Sep 17 00:00:00 2001 From: Christian Krenslehner Date: Fri, 10 Jan 2025 21:24:33 +0100 Subject: [PATCH 1/2] Add file for libloading --- book/src/SUMMARY.md | 2 ++ book/src/libloading.md | 8 ++++++++ 2 files changed, 10 insertions(+) create mode 100644 book/src/libloading.md diff --git a/book/src/SUMMARY.md b/book/src/SUMMARY.md index daaed04081..9e19695ba4 100644 --- a/book/src/SUMMARY.md +++ b/book/src/SUMMARY.md @@ -23,6 +23,8 @@ - [Annotating types with `#[must-use]`](./must-use-types.md) - [Field visibility](./visibility.md) - [Code formatting](./code-formatting.md) + - [Libloading](./libloading.md) + - [Generating Bindings to C++](./cpp.md) - [Generating Bindings to Objective-c](./objc.md) - [Using Unions](./using-unions.md) diff --git a/book/src/libloading.md b/book/src/libloading.md new file mode 100644 index 0000000000..726e0a59b4 --- /dev/null +++ b/book/src/libloading.md @@ -0,0 +1,8 @@ +It is also possible to generate bindings for loading a shared library via the `libloading` crate. +To generate libloading bindings for a library `shared_lib` we can either use the function `dynamic_library_name` function in `build.rs` or the CLI argument `--dynamic-loading` when using the bindgen CLI. + +Here is an example using the bindgen CLI: +``` +bindgen wrapper.h --dynamic-loading MySharedLib --output bindings.rs +``` +Bindgen will generate a `libloading` struct matching the name of the `--dynamic-loading` argument. So in the case of the example above the generated struct will have the name `MySharedLib`. From 6290e77a4c79f23d439fed2a2db305fd5102a0b8 Mon Sep 17 00:00:00 2001 From: Christian Krenslehner Date: Fri, 17 Jan 2025 15:51:41 +0100 Subject: [PATCH 2/2] Update book/src/libloading.md Co-authored-by: Jonathan Schwender <55576758+jschwe@users.noreply.github.com> --- book/src/libloading.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/src/libloading.md b/book/src/libloading.md index 726e0a59b4..2c6865ecae 100644 --- a/book/src/libloading.md +++ b/book/src/libloading.md @@ -1,4 +1,4 @@ -It is also possible to generate bindings for loading a shared library via the `libloading` crate. +It is also possible to generate bindings for dynamically loading a shared library via the [`libloading`](https://docs.rs/libloading/latest/libloading/) crate. To generate libloading bindings for a library `shared_lib` we can either use the function `dynamic_library_name` function in `build.rs` or the CLI argument `--dynamic-loading` when using the bindgen CLI. Here is an example using the bindgen CLI: