Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
O

odin-c-bindgen

> 编程语言
Open source

Generate Odin bindings for C libraries

386 stars0 likes1 views
WebsiteGitHub

About

Generate Odin bindings for C libraries

odin-c-bindgen: Generate Odin bindings for C libraries

This generator makes it possible to quickly generate C library bindings for the Odin Programming Language.

Features:

  • Easy to get started with. Can generate bindings from a folder of headers.
  • Generates nice-looking bindings that retain comments. Example: Generated Raylib bindings.
  • Simplicity. The generator is simple enough that you can modify it, should the need arise.
  • Configurable. Easy to override types and turn enums into bit_sets, etc. More info below and in the examples.

If you find this generator helpful and want to say thanks, then please consider donating.

Discuss and ask questions on my Discord server.

Requirements

  • Odin
  • libclang version 16 or higher
    • On Windows: Download libclang 20.1.8 from here: https://github.com/llvm/llvm-project/releases/download/llvmorg-20.1.8/clang+llvm-20.1.8-x86_64-pc-windows-msvc.tar.xz -- Copy the following from that archive:
      • lib/libclang.lib into the generator's 'libclang' folder
      • bin/libclang.dll into the root of the generator (next to where the bindgen executable will end up).
    • On Linux/mac, please install libclang. For example using apt install libclang-dev on Ubuntu/Debian/Mint. Anything from clang version 16 and newer should work.

[!NOTE] libclang is used for analysing the C headers and deciding what Odin code to output.

Getting started

  1. Build the generator: odin build src -out:bindgen.exe (replace .exe with .bin on mac/Linux)
  2. Make a folder. Inside it, put the C headers (.h files) of the library you want to generate bindings for.
  3. Execute bindgen the_folder
  4. Bindings can be found inside the_folder/the_folder
  5. To get more control of how the generation happens, use a bindgen.sjson file to. See how in the next section, or look in the examples folder.

Configuration

Add a bindgen.sjson to your bindings folder. I.e. inside the folder you feed into bindgen. Below is an example. See the examples folder for more advanced examples.

NOTE: Config uses the function/type names as found in header files.

…

FAQ and common problems

Why didn't my bindings generate correctly?

Please look through the list of configuration options listed above and see if they help you. Also, see the the examples folder for additional inspiration.

If you fail to make any progress on generating bindings for a certain library, then submit an issue on this GitHub page and provide the headers in a zip. I'll try to help if I can find some time.

How can I add some extra code to a generated file?

If the source header is called raylib.h then add a a file called raylib_footer.odin next to it and put your code in there.

How do I manually specify which libraries to load on different platforms etc?

Use imports_file in bindgen.sjson. See examples/raylib

How can I turn an enum into a bit_set?

In bindgen.sjson:

bit_setify = {
	"Enum_To_Turn_Into_Bitset" = "New_Enum_Type_Name"
}

This will replace the type Enum_To_Turn_Into_Bitset (an enum) with a bit_set. The type will look like this: This will create a type Enum_To_Turn_Into_Bitset :: bit_set[New_Enum_Type_Name; i32].

The members that Enum_To_Turn_Into_Bitset had when it was an enum will be moved into a new enum called New_Enum_Type_Name. Within that enum the members will have their values converted using a log2 procedure. The log2 procedure turns for example 2 into 1 and 4 into 2. The bit_set itself will use these numbers to target a specific bit within its backing type.

My headers can't find other headers in the same folder

If the generator is processing include/some_folder/header.h and it can't find some other header include/some_folder/something.h, then add include to the include search path by adding he following to bindgen.sjson:

clang_include_paths = [
	"include"
]

Contributing

If you want to fix issues or add features, then you can create a Pull Request to this repository.

Check out the Issues tab and see if there is something you could help with.

To learn more about how the program works, start by looking in the src/main.odin file. That file loads the bindgen configuration file and then runs procedures in src/translate_collect.odin, src/translate_macros.odin, src/translate_process.odin and src/output.odin. All those files have some comments that try to explain what they do.

Acknowledgements

Big thanks to Xandaron for figuring out a lot of the libclang stuff.

This generator was inspired by floooh's Sokol bindgen: https://github.com/floooh/sokol/tree/master/bindgen

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Cbinding-generatorodinodin-langodinlang

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言