[erlang-questions] Drive by mention of new features without explaination

Jarrod Roberson <>
Mon Dec 7 20:43:51 CET 2009


> http://www.erlang.org/doc/reference_manual/code_loading.html#id2278452

thanks Bob for the link, following those instructions I got this far:

// niftest.c
#include "erl_nif.h"
static ERL_NIF_TERM hello(ErlNifEnv* env)
{
    return enif_make_string(env, "Hello world!");
}
static ErlNifFunc nif_funcs[] =
{
    {"hello", 0, hello}
};
ERL_NIF_INIT(niftest,nif_funcs,NULL,NULL,NULL,NULL)

========================

%% niftest.erl
-module(niftest).
-export([hello/0]).
-on_load(run_me/0).

run_me() ->
      erlang:load_nif("./niftest", 0).
hello() ->
      "NIF library not loaded".

========================

[] [~]
make clean all
rm -f *.o *.beam niftest.so
cc -arch x86_64 -O3 -fPIC -bundle -flat_namespace -undefined suppress
-fno-common -Wall
-I/Users/jrod/Downloads/otp_src_R13B03//erts/emulator/beam/   -c -o
niftest.o niftest.c
gcc -o niftest.so niftest.o -arch x86_64 -O3 -fPIC -bundle
-flat_namespace -undefined suppress -fno-common -Wall
erlc niftest.erl
[] [~]
erl
Erlang R13B03 (erts-5.7.4) [source] [64-bit] [smp:2:2] [rq:2]
[async-threads:0] [kernel-poll:false]

Eshell V5.7.4  (abort with ^G)
1> niftest:hello().
** exception error: undefined function niftest:hello/0
2>

I tried exporting the run_me/0 function as well with the same results?
If I take out the -on_load(run_me/0). and add run_me/0 to the export it works.
Any ideas what I am missing here?


More information about the erlang-questions mailing list