Calling C++ from Elixir

I was trying to spawn different processes which are codes written in C++ (Not C) on different nodes in Elixir. I would be thankful if someone gives me an example how to do it.

2 Likes

It doesn’t make any difference that it’s written in C++. Your choices are still the same: port, nif, or cnode. The latter two will involve importing C header files, but they’re annotated to work in C++ compilers, so that’s not a problem.

There’s wrapper libraries to expose a more idiomatic C++ interface, but I know nothing about them.

1 Like

My whole code is actually written in C++. Is there a good example that shows how I can distribute it on several nodes using elixir processes?

I’m not really sure what are are expecting … AFAIK in any case the compiled C/C++ code already has to be collocated with node.

And writing NIF functions you better really know what you are doing - because it is just too easy to negatively impact the node.

A safer alternative is a C Node (Elixir example) - this essentially allows BEAM processes to talk to code written in C as if it was another process on a different node - but the C code executes in it’s own OS process.

2 Likes