Skip to Content
marmot

Read a C header through clang and write a cgo file with idiomatic Go bindings. Functions get Go types: strings, byte slices, errors from status results, and out parameters as results. Opaque structs become handle types with methods and Close. Enums become typed constants with String, and #define constants become consts. The header's comments become doc comments. What bind cannot decide (who frees a returned pointer, unsupported types) is listed, to be settled in bind.toml. The output is plain cgo and builds with go too.

Usage
marmot bind HEADER [flags]

Examples

marmot bind -o zlib.go zlib.h
marmot bind -config bind.toml -o sqlite3.go sqlite3.h
marmot bind -pkg-config libcurl -o curl.go curl/curl.h

marmot bind reads a C header through clang and writes one cgo file. The output is plain cgo, so go build builds it too. See cgo for how marmot builds cgo packages.

Settle what bind cannot decide in bind.toml: who frees a returned pointer, prefixes, renames and status codes. bind lists these points in its report.

Flags

Flags take one dash or two: -release and --release are the same.

FlagMeaning
-config stringbind.toml with prefixes, renames, status codes and ownership (default: bind.toml beside the output, if any)
-o stringwrite the Go file here (default: standard output)
-pkg stringGo package name (default: from the header name)
-pkg-config stringpkg-config name of the library: its cflags, and #cgo pkg-config in the output
-report stringwrite the report (what was not bound and why) here too

Full help

marmot bind --help
Read a C header through clang and write a cgo file with idiomatic Go bindings. Functions get Go types: strings, byte slices, errors from status results, and out parameters as results. Opaque structs become handle types with methods and Close. Enums become typed constants with String, and #define constants become consts. The header's comments become doc comments. What bind cannot decide (who frees a returned pointer, unsupported types) is listed, to be settled in bind.toml. The output is plain cgo and builds with go too.

Usage:
  marmot bind HEADER [flags]

Examples:
marmot bind -o zlib.go zlib.h
marmot bind -config bind.toml -o sqlite3.go sqlite3.h
marmot bind -pkg-config libcurl -o curl.go curl/curl.h

Flags:
      --config string       bind.toml with prefixes, renames, status codes and ownership (default: bind.toml beside the output, if any)
  -h, --help                help for bind
      --o string            write the Go file here (default: standard output)
      --pkg string          Go package name (default: from the header name)
      --pkg-config string   pkg-config name of the library: its cflags, and #cgo pkg-config in the output
      --report string       write the report (what was not bound and why) here too

On this page

Was this page helpful?

Report an issueOpen issues