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:
"terminal.integrated.shellArgs.windows": [
"/K",
"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
INCLUDE
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
LIB
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.15.26726\lib\x64
PATH
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