[erlang-questions] Linking enif_* functions to an executable file

Michael Santos michael.santos@REDACTED
Sat Apr 26 17:05:07 CEST 2014


On Sat, Apr 26, 2014 at 11:38:33PM +0900, mayamatakeshi wrote:
> Hello,
> I am having trouble to debug a NIF library that I wrote (and somehow I
> cannot make gcc to stop when a crash happens in it).

Might be simpler to use gdb:

http://blog.dizzyd.com/blog/2009/12/18/running-erl-in-a-debugger/

There is also the cerl script in the otp source which will run beam
under gdb.

> So I would like to test the NIF in an executable like this:
> 
> static ERL_NIF_TERM nif_myfunc(ErlNifEnv *env, int argc, const ERL_NIF_TERM
> argv[]) {
>     ... do something with enif and native functions ...
> }
> 
> void main() {
>     ErlNifEnv *env = enif_alloc_env();
>     nif_myfunc(env, 0, 0);
> }
> 
> But it seems enif_alloc_env is not present in any lib*.a or *.so that gets
> generated when I build erlang.
> I tried to link to the beam (renamed as libbeam.a)) but i got the linker to
> segfault. So I might need to extract these definitions or extract them from
> the beam source code and add it to my app, but it looks too much trouble.
> 
> So, is there a simple way I can do this?
> 
> Regards,
> Takeshi

> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list