How it works...
bindgen is an amazing tool that generates Rust code from C/C++ headers on the fly. In step 1 and 2, we added the dependency and used the bindgen API to load the header and generate and output a file called bindings.rs in the temporary build directory. The OUT_DIR variable is only available from within cargo's build environment and leads to a directory containing several build artifacts.
Additionally, the linker needs to know about the library that has been created so it can link to it. This is done by printing out the required parameters to standard with a special syntax. In this case, we pass the library's name (link-lib) and the directory it should check (link-search) to the rustc linker. cargo can do much more with these ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access