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.


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 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.

1 Like

Exactly, the documentation is here:

You basically need Visual Studio, and make the dependencies available on the path.
For the record, this can be relatively straightforward. Using, you can do this:

PS> Import-VisualStudioEnvironment
PS> mix compile

And then everything works for me.