← 返回命令列表

Linux command

cbindgen 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Generate C header from Rust library

cbindgen -o [header.h]

Generate C++ header

cbindgen --lang c++ -o [header.hpp]

Generate C header explicitly

cbindgen --lang c -o [header.h]

Use specific config file

cbindgen --config [cbindgen.toml] -o [header.h]

Generate from specific crate

cbindgen --crate [crate_name] -o [header.h]

Show help

cbindgen --help

说明

cbindgen generates C and C++11 headers from Rust libraries that expose a public C API. It parses Rust source code and creates corresponding C declarations for FFI-exported types and functions. Developed by Mozilla, it ensures generated headers match Rust's type layout and ABI guarantees.

参数

-o, --output _file_
Output header file path
--lang _language_
Output language: c or c++ (default: c++)
--config _file_
Path to cbindgen.toml configuration
--crate _name_
Crate name to generate bindings for
--profile _name_
Cargo profile to use
-v, --verbose
Enable verbose output
-q, --quiet
Suppress output
--verify
Verify existing header matches generated
--help
Show help

FAQ

What is the cbindgen command used for?

cbindgen generates C and C++11 headers from Rust libraries that expose a public C API. It parses Rust source code and creates corresponding C declarations for FFI-exported types and functions. Developed by Mozilla, it ensures generated headers match Rust's type layout and ABI guarantees.

How do I run a basic cbindgen example?

Run `cbindgen -o [header.h]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -o, --output _file_ do in cbindgen?

Output header file path