[erlang-questions] Error from on_load function of NIF module
Igor Clark
igor.clark@REDACTED
Wed Jan 6 19:19:35 CET 2016
Hi Abhishek,
I'm fairly new to writing NIFs, so forgive me if you've already tried
everything here, but this type of error is very familiar from when I
first tried building NIFs with external C/C++ library dependencies on
OSX. Eventually I gave up writing my own Makefile and just let rebar do
everything, and the errors went away :-D
Anyway, I tried to build your "merger" project just now, and neither
"make" nor "make all" seemed to be building the ucol collate_json.o file
by default. Trying to run "make utf" against OSX's default icu libs
afterwards didn't work either ("fatal error: 'unicode/ucol.h' file not
found").
So I brew-installed & force-linked the homebrew icu4c lib, at which
point "make utf" worked, and then merger:new/0 worked straight away:
> $ erl -pa ./ebin
> Erlang/OTP 18 [erts-7.1] [source] [64-bit] [smp:8:8]
> [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
>
> Eshell V7.1 (abort with ^G)
> 1> merger:new().
> {ok,<<>>}
Of course there may be other subsequent errors on trying to do anything
more with it, but it looks at least like the NIF is loading OK for me,
on both OSX 10.9.5 and 10.10.5. So I think it might be something to do
with your environment there.
Like I said, you may well know way more about this than I do, but if
this was me, here are some things I'd look into:
- try a more recent erlang version, from your Makefile it seems you have
erts-5.10.4.0.0.1 and erl_interface-3.7.15 whereas my Homebrew erlang
install has 7.1 and 3.8 respectively.
- try using icu4c from homebrew, the UTF stuff in this project wouldn't
build for me with the default OSX icu libs.
- tweak the targets using "deps" in the Makefile; I get "make: Circular
deps <- deps dependency dropped." when running "make" on it.
- most of all, try getting rebar to do all the C compilation for you.
For my NIFs, at least, I just tell it about external lib deps with
CFLAGS/CXXFLAGS/LDFLAGS, and it orders everything correctly along with
the flat-namespace stuff without me having to think about it. YMMV.
BTW if anyone knows explicitly why the error is happening, rather than
just "try to fix it with rebar magic", I'd love to know that too ;-)
Cheers,
Igor
On 06/01/2016 05:55, Abhishek Singh wrote:
> Hi,
>
> I’m trying to get NIF implementation of unicode collation integrated into a database. Erlang module trying to load NIF: https://gist.github.com/abhi-bit/3aea4ff78ffb52820260
>
> During on_load function call, I’m seeing below error:
>
> The on_load function for module merger returned {error, {bad_lib, "Failed to find library init function: 'dlsym(0x7fa288718b30, _nif_init): symbol not found'”}}
>
> Any suggestion why that could be happening here? NIF C code lives under https://github.com/abhi-bit/merger for reference.
>
> /Abhi
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
More information about the erlang-questions
mailing list