I am trying to create a simple NIF DLL on Windows 10 (64 bits) using GCC compiler. Here is my command line:
gcc -I<my\include\path> -o my_nif.dll -fpic -shared my_nif.c
When I do this, I am getting a linker error: “Undefined reference to WinDynNifCallbacks”
Do I have to link this with any elixir LIB file to avoid the error?
Similarly, if I were to use Visual Studio for building this DLL, what option should I use?
Thanks for your help.
You are in for a lot of pain compiling C/C++ on Windows.
I’d suggest first installing the full Visual Studio C/C++ stack (including redistributable .DLL files) and try to work with
nmake first. If that doesn’t work then try MinGW32 and gcc.
We can’t help much here with these problems here, save for a few recommendations.
Thanks. I will follow your suggestion.
You might also look at https://github.com/riverrun/bcrypt_elixir for inspiration, this is a library that uses NIF and works on Windows too.
Since when? I thought the officially propsed hasher for windows was pbkdf2 as it has a pure elixir implementation…
There’s documentation by riverrun to make all his hashers compile on windows. Though, it’s not the straight forward type of getting it to do so.
Exactly, the documentation is here: https://github.com/riverrun/comeonin/wiki/Requirements#windows
You basically need Visual Studio, and make the dependencies available on the path.
For the record, this can be relatively straightforward. Using https://github.com/olegsych/posh-vs, you can do this:
PS> mix compile
And then everything works for me.