In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to use the Bindgen tool in Rust FFI programming. I think it is very practical, so I share it with you. I hope you can get something after reading this article.
Bindgen introduced us to introduce the rust-bindgen project. The project address is: https://github.com/rust-lang/rust-bindgen. As you can see, this is an official incubation project of Rust, which is quite mature at present. This article is only a general introduction, not a complete explanation of the bindgen project, nor a comprehensive translation of bindgen tutorial. Therefore, when you really do it, you need to carefully read the original Tutorial text and consult the relevant API. Bindgen is an auxiliary library and command-line tool that automatically generates Rust bindings for C (or C++) libraries. C++ 's (currently) support is incomplete. In other words, bindgen can be used as a crate, in conjunction with Cargo's build.rs mechanism, to automatically generate Rust binding files during the build phase before compiling the body Rust code according to the header file (.h, .hpp) of Cmax Candle +. Specifically, check out the example: https://rust-lang.github.io/rust-bindgen/tutorial-0.htmlbindgen has another use, which itself provides a command-line tool. Execute: cargo install bindgen
It can be installed. Then, at the command line, use the
Bindgen input.h-o bindings.rs
The Rust binding file bindings.rs can be generated dynamically according to the C header file input.h. It's simple. But the real scene is not as pure as imagined. So there is a lot of possible repair work. Bindgen provides us with various ways to fix it (this is the essence). Specifically, there are the following measures: whitelist blacklist Opaque object type replacement some of these measures can be used in library mode, command line mode, and in the source code (C) comments to add annotations in the mode. Some can cover all three, and some can only cover one or two of them. A detailed explanation can be found on the https://rust-lang.github.io/rust-bindgen/customizing-generated-bindings.html page. At the same time, bindgen also has corresponding strategies to deal with the characteristics of Union and Bitfields of C. These may often be encountered in the actual packaging process. Bindgen itself is not very knowledgeable. The above is how to use the Bindgen tools in Rust FFI programming. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.