# C Bindings

**URL:** <https://forum.crystal-lang.org/t/c-bindings/1518>\
**Category:** Help & Support\
**Created:** [December 20, 2019, 3:39pm UTC](https://forum.crystal-lang.org/t/c-bindings/1518 "2019-12-20T15:39:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ejstembler](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/ejstembler/32/553_2.png) [@ejstembler](https://forum.crystal-lang.org/u/ejstembler)\
**Post date:** [December 20, 2019, 3:39pm UTC](https://forum.crystal-lang.org/t/c-bindings/1518/1 "2019-12-20T15:39:05Z")

</div>

I’m interested in writing bindings to a 3rd-party C API. I’ve looked over the [C Bindings](https://crystal-lang.org/reference/syntax_and_semantics/c_bindings/), though I was wondering if there’s an end-to-end project example somewhere? Something which illustrates code and file structure, conventions, etc. I’m not sure where to begin, and a full/complete example would be helpful.

---

<div class="post-metadata">

**Author:** ![bcardiff](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/bcardiff/32/3_2.png) [@bcardiff](https://forum.crystal-lang.org/u/bcardiff)\
**Post date:** [December 20, 2019, 6:22pm UTC](https://forum.crystal-lang.org/t/c-bindings/1518/2 "2019-12-20T18:22:11Z")

</div>

libllvm, libcrypto, libssl from the std-lib are some examples.

Other examples:

- [https://github.com/crystal-lang/crystal-sqlite3](https://github.com/crystal-lang/crystal-sqlite3)
- [https://github.com/ysbaddaden/sdl.cr](https://github.com/ysbaddaden/sdl.cr)

Using [crystal-lang/crystal\_lib](https://github.com/crystal-lang/crystal_lib) might be helpful. But if you are not fully aware of all the C api it might be better to start small. That is the approach I use for example in [https://github.com/bcardiff/crystal-z3](https://github.com/bcardiff/crystal-z3) to play a bit with the object model of the API.

Usually `libfoo.cr` will have the `@[Link]` and raw types. A `foo.cr` will require it and define some API and names in a more crystal way.

---

<div class="post-metadata">

**Author:** ![ejstembler](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/ejstembler/32/553_2.png) [@ejstembler](https://forum.crystal-lang.org/u/ejstembler)\
**Post date:** [December 20, 2019, 8:50pm UTC](https://forum.crystal-lang.org/t/c-bindings/1518/3 "2019-12-20T20:50:32Z")

</div>

Thanks Brian!
