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.
I tried setting the C_INCLUDE_PATH environment variable:
export C_INCLUDE_PATH=/usr/lib/erlang/usr/include
and tested that CPP would use it with cpp -v /dev/null -o /dev/null returning
#include <…> search starts here:
/usr/lib/erlang/usr/include
/usr/lib/gcc/x86_64-pc-linux-gnu/13.1.1/include
/usr/local/include
/usr/lib/gcc/x86_64-pc-linux-gnu/13.1.1/include-fixed
/usr/include
End of search list.
I also tried setting CMAKE_INCLUDE_PATH env variable with no joy.
Then attempting to recompile after cleaning and getting the deps again the same error is given. Same result after trying to alias cpp to include the path:
alias cpp=“cpp -I/usr/lib/erlang/usr/include”
How can I get cmake to actually find the header in this location? FWIW I’m on Arch and installed erlang and elixir with pacman.
EDIT with sort-of-solution:
Well, I was able to get it to compile by manually editing deps/alex/src/nifpp.h after mix deps.get but before mix deps.compile. Changing the line #include <erl_nif.h> to #include </usr/lib/erlang/usr/include/erl_nif.h> seemed to do the trick. I would still like to know how to implement a more global solution than manually editing the paths every time.
EDIT2 with better sort-of-solution: Answer to this issue on github that works for me. I’m not sure why that works but my alias attempt failed. Are there any downsides to having CXXFLAGS set to include the erlang include path even if it’s not needed?