Linking to C library

I’m new to Elixir. One of the first projects I want to do needs to use the ICU library. The project is talking to old main frames which use different EBCDIC code pages (yea… there is more than one EBCDIC). ICU is the only library I’ve found over the years that knows them all. There is a Ruby binding to it that I’ve sorta taken over maintenance of. I will need to create a similar binding for Elixir. I cruised very quickly for a how to but didn’t find it.

I also surfed for this for Erlang and found some hits. e.g. It seems there is also the concept of a “port”.

Any suggestions would be appreciated.

Oh… and, for a fun time, try searching for “ICU Elixir” All sorts of fun hits come up.


There are two ways to go: The fast but dangerous way ( nif ) and the slower but safer way ( Port).

Nifs are the way that you can add an interface to an existing C library to the BEAM, however there are a bunch of gotcha’s. The most important is that if your NIF crashes the entire BEAM crashes.

A Port is a safer way to deal with external code, essentially it’s a mini-server that runs whatever code in a separate process and allows the BEAM to send messages back and forth.

There is a project that supports using Ports between Ruby and Erlang/Elixir.
You could likely use that to communicate to your Ruby API.


Don’t forget the elusive C Node (, which I keep hoping to scratch some time together to experiment with more.

In theory, you’d be able to make distributed calls to your C lib that is wrapped in a C Node and not worry about it crashing your application node.

I’ve used ports quite a bit and they are fine, but there are some scenarios where I think this approach would be excellent - I just need to research it more.