Library module name 'foo_nif' does not match calling module 'erl_eval'

9 Oct 2014 13:43 erlang nif

It turns out that you can’t load Erlang NIF libraries from the shell.

If you try, you get the following error:

{error,{bad_lib,"Library module name 'foo_nif' does not match calling module 'erl_eval'"}}

Instead, you have to put together an Erlang module, looking something like the following, and load that.

-module(foo_nif).
-on_load(on_load/0).

on_load() ->
    % Note that the ".so" suffix is assumed.
    Path = ?MODULE,
    ok = erlang:load_nif(Path, 0).