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

Daniel Goertzen <>
Sat Apr 26 17:04:52 CEST 2014


The NIF API is made to be used in the presence of a running emulator, so I
don't think this approach will ever work.  Some suggestions:

1. Debug with printf().
2. Take your approach above but rip out all the NIF APIs to see if *that*
works.

Dan.



On Sat, Apr 26, 2014 at 9:38 AM, 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).
> 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
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140426/98ff65e5/attachment.html>


More information about the erlang-questions mailing list