Hey. I am trying to get the Hello World example for Erlang NIF (Native Implemented Function) shown here. http://www.erlang.org/doc/man/erl_nif.html for working with Elixir on OSX 64bit.
First I create C code:
#include "erl_nif.h" static ERL_NIF_TERM hello(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) { return enif_make_string(env, "Hello world!", ERL_NIF_LATIN1); } static ErlNifFunc nif_funcs[] = { {"hello", 0, hello} }; ERL_NIF_INIT(niftest,nif_funcs,NULL,NULL,NULL,NULL)
Then I will successfully compile it with gcc for 64-bit architecture, as suggested here by Erlang NIF Test - OS X Lion
gcc -undefined dynamic_lookup -dynamiclib niftest.c -o niftest.so -I /usr/local/Cellar/erlang/R14B02/lib/erlang/usr/include
which creates the necessary niftest.so file that I could interact with in Erlang / Elixir. My Elixir (niftest.ex) looks like this (using a more complex example here ):
defmodule Niftest do @onload :init def init() do :erlang.load_nif("./niftest", 0) :ok end def hello() do "NIF library not loaded" end end
Now with niftest.so and niftest.ex in the same directory, I run the elixir using iex and type Niftest.hello , and all I return is: "The NIF library is not loaded"
Did I miss a vital step? - please, help!
erlang elixir native macos erlang-nif
Gavin brelstaff
source share