Building NIF on Windows

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.

Regards,
Rangarajan

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 GitHub - riverrun/bcrypt_elixir: Bcrypt password hashing for Elixir · GitHub 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: Requirements · riverrun/comeonin Wiki · GitHub

You basically need Visual Studio, and make the dependencies available on the path.
For the record, this can be relatively straightforward. Using GitHub - olegsych/posh-vs: Makes Visual Studio command line tools available in PowerShell · GitHub, you can do this:

PS> Import-VisualStudioEnvironment
PS> mix compile

And then everything works for me.