Tools
fb bindgen
Turns a C header into a FutureBlitz module.
fb bindgen <header.h> [options]fb bindgen reads a C header with libclang, which fb ships, and writes a module of its
declarations:
- a
@CLayoutStruct for each struct; - an Enum, or Consts, for each enum;
- a Const for each macro that’s a number;
- one
Public Extern "C" Libblock of its functions.
What can’t map, like a union or a function that takes varargs, is a // skipped: comment that
says why. It needs no C compiler: fb has the C headers each target’s programs build against, and
on macOS it reads the SDK’s, from Apple’s Command Line Tools.
Options
| Option | |
|---|---|
-o, --output <file> | Where the module goes; without it, <header>.fb in the current folder |
--lib <name> | The [native] library its Extern block names; without it, the header’s name, and "" for none |
--target <triple> | The target to read the header for; without it, the one fb builds for |
--std <standard> | The C standard to read it with, like c17 |
-I <folder> | A folder the header’s #includes are found in |
-D <name>[=<value>] | Defines a macro |
--color <when> | Colors the output: auto, always, or never |
Examples
fb bindgen include/sqlite3.h --lib sqlite3 -o sqlite3.fb
fb bindgen vendor/lib.h -I vendor/include -D LIB_STATICThen [native] in project.toml says where the library is, and Import "./sqlite3" uses the
module. Using a C library goes through it step by step.
Report an issue with this page or with FutureBlitz on GitHub.