# marmot bind (/docs/commands/bind)

<!-- Generated by scripts/gen.mjs from `marmot bind --help` and scripts/commands.mjs. Do not edit by hand. -->

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.

```text title="Usage"
marmot bind HEADER [flags]
```

## Examples [#examples]

```sh
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](/docs/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]

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

| Flag | Meaning |
| --- | --- |
| `-config string` | bind.toml with prefixes, renames, status codes and ownership (default: bind.toml beside the output, if any) |
| `-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 |

## Full help [#full-help]

```text title="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
```