Making NIFs easier to work with on Windows 10 (And making work Elixir-ls too)

So my main OS is Windows, I do must of my work with it, Elixir and vscode elixirls works just fine when you’re working only with elixir, but when you’re working with nifs (more specifically the C/C++ code) can became really annoying to work with, this because of the compilation process of the Nifs

I endup running visual code on WSL, but today it stop working and corrupted all the permissions on the project I was working on (fortunatelly I was able to recover the data using linux dual boot), so I decided to look a way to simplify the windows development and make it work with elixir-ls as well, this is the result of my findings and how it solves all the problems I’ve faced before so far

This guide applies using Visual Studio 2017 Professional, but it must work with other versions as well, you just need to change the path

Getting the compiler and the path of the file “vcvarsall.bat”

If you have compiled nifs befores, you must already know that this is the great wall.

You must install Visual Studio 2017 (but it should work with older versions as well), make sure to have marked the option “Desktop Development with C++” it should install VC++ which contains the file, on the last version of VS is located at C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build, if is not, just go to your Visual Studio install folder and search for the file

Note: You must install Visual Studio with the English language pack!, I had the Spanish version and elixir-ls throws errors when it must print on console a diacritical character

- I only want to compile my files easier using VSCode, I don-t make use of ElixirLs

In that case you must chage the settings.json of VisualCode, adding this:

    "": [
        "C:\\PROGRA~2\\MICROS~1\\2017\\Professional\\VC\\Auxiliary\\Build\\vcvarsall amd64"

the second argument is the vcvarsall path location and the amd64 parameter

- I want to compile and make work ElixirLS

This solution is taken from this link, it covers older versions of Visual Studio, basically what vcvarsall does is setting up env variables during the session to make the compile, to make ElixirLS work we must set those variables manually, here’s the variables to set

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.15.26726\include;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.15.26726\atlmfc\include

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.15.26726\lib\x64

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.15.26726\bin\Hostx64\x64

This might change depending the on the version, but if you look carefully all the folders you want are inside the VC folder

With this method you can compile your nif code from a normal CMD or powershell without the need of calling the vcvarsall script!

(this will solve your issues compiling Bcrypt! Yei!)

So that’s all, if you see any grammar error, do not understand the explanation, need specific details or have a better option to solve it please let me know or feel free to edit the post :smiley:


For note, I had many issues with wsl so I ended up just using a normal mingw setup and never had issues after that once I got it all set up back when I still had to program on windows (blehg).

1 Like

Oh sure it is an option too, tho I don’t have good memories from the time I was using mingw, so I decided to look for a more native solution

Personally I’m really used to Windows since it has already all the things I like and all my games, tried to move to linux and such but never liked it, the designs are awfull and I faced more problems on linux desktop than windows tbh ^^’

It is a bit of a pain to setup, but the installer for it nowadays are pretty rock solid to get a fully setup area for you now.

Really, give Kubuntu (18.10) a try, I’ve converted SO many people off Windows to it. And as for games you do know that Steam has a fully built in Wine support now (with whitelisted games by default or enable for all games via an option settings if you don’t mind the occasional package installation into a games prefix, protontricks is awesome for that, or just use wine straight for things not in steam). Not sure what ‘designs are awful’ you speak of, considering every distribution is incredibly different in many ways. As for problems, wow that incomparable in my experience, the amount of issues Windows gets at work and on friends systems (prior to linux conversion) is astounding, linux “Just works” (I don’t use laptops though but 2 of my friends that converted to linux on their laptops works perfectly, I know in the past there used to be issues though but it’s pretty solid now). As for gaming, nVidia’s drivers, as always, suck horribly, a modern AMD (or even Intel) setup is so much more stable than nVidia’s crashy binary blobs…

1 Like

So the part to make work with elixirLS do I add the variables into environment variables in windows, there only Path in system, does that mean I create new variable called INCLUDE and add the path to it

yeah you must create INCLUDE and LIB if it does now exist

Oh man I added the same thing as you, well minus \atlmfc\include as I have VCBuildtools installed and not visual studio itself.

currently only vcvarsall that works, which is fine but ElixirLS give me an error in my mix.exs file because of bycrypt can’t find nmake to compile even though it compiles fine in vscode terminal.

it seems I did something wrong, or something is missing

>echo %INCLUDE%
>C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\include
>echo %LIB%
>C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\lib\x64

>echo %PATH%
>...C:\ProgramData\chocolatey\lib\Elixir/bin;C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64;C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\IDE; 

If I can’t get it to work might as well install ubunutu in Hyper-V and be done with it.

Have you check out all the paths exists in your pc?

When you open a normal CMD or powershell and then you run cl and nmake it works or no?

Yeab both works fine in normal cmd

Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24210 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

usage: cl [ option... ] filename... [ /link linkoption... ]


Microsoft (R) Program Maintenance Utility Version 14.00.24210.0
Copyright (C) Microsoft Corporation.  All rights reserved.

NMAKE : fatal error U1064: MAKEFILE not found and no target specified


So I got it working and I will leave it here for future reference to everybody, Windows by default doesn’t load env vars because it want your environment var clean and load only what you need through the bat file like amd64 or arm64 … etc

what I did is to try and compile bycrypt and take note of the file that cmd find missing for example it might say can’t find INCLUDE stdio.h, so you search for the file in windows and copy the path into environment (if it found multiple copies then choose the one in x64 or amd64 folder) variables in windows and paste it in INCLUDE, same thing it will says it couldn’t find LIB kernel32, you repeat the same step as before but instead you put it inside LIB env.

in the end the missing environment variable for me were:

C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17763.0\ucrt\x64
C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17763.0\um\x64

C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um

Never in my experience? It always loads all and every single environment variable specified.

If you are missing headers that generally just means you never set the env-vars. If using Visual Studio it won’t add them, you can either add them yourself or call a script it made to auto-add them into the current environment. If using something else that all depends. Regardless, any of the methods you can add globally if you so wish.