Where is erl_nif.h header file required for NIF?

Please help me.

I am trying to write C code of NIF referring to the following article.

However, an error occurs because the header file cannot be found.
gcc nif.c
nif.c:1:10: fatal error: erl_nif.h: No such file or directory
#include “erl_nif.h”
compilation terminated.

Where is erl_nif.h header file required for NIF ?
Please tell me what to do.

My environment is Windows subsystem for LInux, Ubuntu 18.04.

Depending on how you installed erlang, you might need to install additional packages.

If you installed erlang and elixir through apt (but not from ESL repos), it might be that sudo apt install erlang-dev works.

If though you installed by any other means, then you will need to check how you install the erlang headers via that package/version manager.


Thank you for your quick advice.
I’ll try.

It went well.
Thank you very much.

hello , i ma having same problem on windows.

Please how did you eventually resolve this?

I implement it on Linux. I have not checked on Windows. But the following code may be fine.

I referred to Matrex makefile code.

ERL_INCLUDE_PATH = $(shell erl -eval ‘io:format("~s", [lists:concat([code:root_dir(), “/erts-”, erlang:system_info(version), “/include”])])’ -s init stop -noshell)

nifs: ./lib/nifs.cu
@mkdir -p priv
nvcc -shared --compiler-options ‘-fPIC’ -lcublas -I$(ERL_INCLUDE_PATH) -o ./priv/nifs.so ./lib/nifs.cu

That code gives the PATH to the Nif header.

1 Like

I found that it could be simpler to run elixir --eval ":code.root_dir()"