How to fix "could not compile dependency :bcrypt_elixir" error on Windows?
Asked Answered
D

8

8

I'm on Windows and I am trying to install the bcrypt_elixir module.

I get the following error:

$ mix phx.server
==> bcrypt_elixir
could not compile dependency :bcrypt_elixir, "mix compile" failed. You can recompile this dependency with "mix deps.compile bcrypt_elixir", update it with "mix deps.update bcrypt_elixir" or clean it with "mix deps.clean bcrypt_elixir"
** (Mix) "nmake" not found in the path. If you have set the MAKE environment variable,
please make sure it is correct.

Here is a terminal screenshot of the error:

Error

Here is my deps function from mix.exs:

defp deps do
    [
      {:phoenix, "~> 1.3.0"},
      {:phoenix_pubsub, "~> 1.0"},
      {:phoenix_ecto, "~> 3.2"},
      {:postgrex, ">= 0.0.0"},
      {:phoenix_html, "~> 2.10"},
      {:phoenix_live_reload, "~> 1.0", only: :dev},
      {:gettext, "~> 0.11"},
      {:cowboy, "~> 1.0"},
      {:comeonin, "~> 4.0"},
      {:elixir_make, "~> 0.4.1"},
      {:bcrypt_elixir, "~> 1.0"}
    ]
  end
Decent answered 24/3, 2018 at 23:59 Comment(0)
B
12

I faced same problem during distillery setup with my elixir project.

Installing package resolve issue as shown below.

I found bcrypt_elixir need to install make and build-essential from Elixir Forum.

platform:- ubuntu

$ sudo apt install make

$ sudo apt-get install build-essential

Bensen answered 24/1, 2019 at 9:45 Comment(7)
this problem is on windows, so this answer is totally out of context.Jackelynjackeroo
@Jackelynjackeroo Sir when user get this issue , they get this statement "could not compile dependency :bcrypt_elixir" and people simply put in google to get solution. This question get on first in Google SEO. Suppose any Linux user got this issue and he/she will reach on this problem web page and they will get their solution so I put. This is the beauty of stack overflow to help the people by the people's answers. Rest things I am leaving up to your understanding.Bensen
it will be difficult to have this problem on ubuntu, in any case.Jackelynjackeroo
@Jackelynjackeroo I have faced this issue when i was building binary with the help of distillery. in case if you want i can re-produce.Bensen
You ran into this error cause you didn't read the installation docs on github: github.com/riverrun/bcrypt_elixir where they clearly say you need a C compiler installed, I mean no one requires you read the whole docs, but at least "how to install" should be known.Jackelynjackeroo
@Jackelynjackeroo Please focus on that you down voted this answer because it was answered for Ubuntu platform not because of installations stuff. So let me tell you there are so many question which are/were asked for RPM but people answered for Debian based too.Bensen
@ShreePrakash I did get that problem on Ubuntu because I had not installed build-essentials, so thank you!Norvall
J
6

For Visual Studio 2019 (VS2019) :

cmd /K "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64
Jackelynjackeroo answered 10/11, 2019 at 12:14 Comment(0)
D
4

bcrypt_elixir uses Windows' NMake (cf. bcrypt_elixir's Makefile.win).

It seems like you don't have NMake installed.

From NMake's documentation:

NMAKE is included when you install Visual Studio or the Visual C++ command-line build tools. It's not available separately.

So you need to download Visual Studio in order to get NMake. Then you should be able to compile bcrypt_elixir.

If you already have NMake, make sure nmake.exe is located under a directory from your path.

Doctor answered 25/3, 2018 at 0:56 Comment(6)
I downloaded and installed visual studio and it didn't fix the problem. I searched for a file named nmake.exe and nothing came up.Decent
Also take a look at this page--it's for ComeOnIn but the steps he outlines apply here too.Zoo
Look a little closer @RonanBoiteau--he's running Cygwin. Nmake doesn't even enter into it.Zoo
For Visual Studio 2019, I needed to install the optional Desktop Development with C++ workload. I'm sure you could find the individual component to install as well, I'm just not sure which one it is.Pirri
This is from the exqlite package docs, but I think it will be helpful for any package that relies on nmake: hexdocs.pm/exqlite/windows.htmlPirri
I followed the steps described in the Comeon wiki but I don't have the folder 'Microsoft Visual Studio' after installing the C++ Build Tools it makes reference to. It seems like the docs are missing the step to install Visual Studio then. I'm on Windows 11 Pro 64xMurat
B
3

Windows uses "nmake" in place of Linux's "make" to compile "bcrypt_elixir".

You would need to install "nmake"; and you can only get it by installing "Visual Studio".

Follow these steps:

  1. Go to this link https://visualstudio.microsoft.com/ and download Visual Studio (I downloaded the Community version)

  2. Install the downloaded file. I have both 2019 and 2022. Use 2022 version for everything onwards.

At this stage, you must have already gotten the nmake (skip to step 4, if you have). If you haven't yet, proceed through the next steps

  1. Click on "modify". It takes you to a pop-up where you click on and download the "Desktop development with C++" (this is the Microsoft C++ Build Tools). It appears first on the list (it shows about 9gb as expected device memory space to be used, but the file is actually not up to 2gb. You would see when you start to download). Install it as well.

  2. Open your folder directory using the File Explorer and go to your Phoenix/Elixir project. Copy the link of the directory. Mine is: C:\Users\maxim\Desktop\Projects\Sample-Projects\real_deal_api

Open your cmd terminal and cd into it like so:

cd C:\Users\maxim\Desktop\Projects\Sample-Projects\real_deal_api
  1. Open a fresh cmd terminal and type in the following command to see all nmake files on your device. And change directory to the main root of your device. (If you type the nexty command elsewhere, you won't find the nmake file):

    cd ../..

(Add as many "../" as you need to get to the main root. For me, my main root is C drive (C:>)). So, I used the cd ../.. above.

then, type in the following command to list out all the nmake files.

dir /s nmake.exe
  1. Select the path to the particular nmake file that matches your device.

Mine is like so:

C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64

I am running a 64-bit Windows laptop. Find out yours.

(To find out how many bits yours is, go to the Windows search on the left-bottom of your screen and type in "system information" or better yet, type "Control Panel" and click on "System". It shows you your system information. This will inform our choice of path.)

  1. Go to your Windows search again and type in "environment variables". click on "Edit the system environment variables". A pop-up comes up. Click on "Environment Variables..." button.

Within "System variables", which is the second window, double-click on "Path" (or click on it and click on "Edit button").

Add the exact generated directory link of the nmake file to the list of paths you see. By clicking on "New" and make sure you save with "OK' at the end of it all. Click "OK" button again at the "Environment Variables" dialog box screen.

  1. Run:

    mix deps.compile

on the elixir/phoenix project directory and copy the command it spits out for you to run. Mine is:

cmd /K "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" amd64

Take note of the "vcvarsall.bat" file. That file is what enables us to run the next commands.

Change directory (cd) into the root directory again as we did in step 5 above and run the command given on this step 8 as given by your application when you ran the "mix deps.compile" command.

  1. The last command has activated the "vcvarsall.bat" file under the hood to enable you compile your elixir/erlang file that isn't compiling ordinarily. Do not close this instance of the cmd prompt. Else, you would lose the power (from the "vcvarsall.bat" file) to compile the stubborn elixir/erlang files.

If you close it, you would have to start again from step 8 in order to be able to compile your stubborn file.

  1. Go to your already open and running cmd prompt and change directory (cd) into the elixir/phoenix project you are working on. Mine (directory) is: C:\Users\maxim\Desktop\Projects\Sample-Projects\real_deal_api

  2. Finally, re-run your command "mix deps.compile". It should compile at this point.

You can go back to your VS Code and continue to run your regular commands from the terminal as you wish or any other terminal you might be using.

If this isn't clear enough and you would like images, comment below, so I can add them. But I believe this explanation should be pretty straightforward as I took time to explain in details.

Brawley answered 18/5, 2023 at 17:4 Comment(1)
I would like to add that you will have to install that you spesificlly need the C++ Desktop one in visual studio installer. for step 2.Teddie
D
2

In windows 10, you must add NMAKE to your path enter image description here

After that you can run mix deps.compile until see message like this: enter image description here

After that you must run cmd as suggest from nmake:

cmd /K "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64

Run this command on cmd and run mix deps.compile normarly.

Domesday answered 27/3, 2020 at 3:2 Comment(0)
Z
1

Actually looking at this a bit closer, since you're running Cygwin and trying to build bcrypt under Cygwin, nmake doesn't even enter into the question. You need to install make into Cygwin. Re-run the cygwin installer, select the Devel category and then under Devel look for make.

EDIT:

Ok, so if I had to guess I'd say either you need to

a.) Stop trying to build everything under the Cygwin prompt--if bcrypt_elixir is detecting that it's on Windows, it's going to look for nmake and nmake isn't part of Cygwin.

You didn't specify how you're looking for nmake but if I were you I'd try this from the C:\Program Files (x86) directory.

dir /s nmake.exe

Mind you run that from a Windows cmd prompt--it won't work from the Cygwin shell!

b.) Somehow set bcrypt_elixir to think it's on Linux so it looks for make (which is not the same as nmake).

Basically I think the simplest answer would be to try to run mix phx.server from a normal Windows cmd prompt and then go from there. Or if you need Linux, then install virtual box and put a Linux VM on the machine and proceed that way.

Zoo answered 26/3, 2018 at 21:28 Comment(0)
D
1

I found that, running on Windows, it was the latest version of erlang OTP, version 21, that was causing the problem. I uninstalled this version and went for version 20 (which installs erlang 9.3 and latest version of Elixir then looks for this version when being compiled) and then bcrypt_elixir compiled al

Devious answered 29/7, 2018 at 16:54 Comment(0)
P
1

This answer is for anyone running elixir directly on Windows, and using VS Code with the ElixirLS extension. These instructions should work for other Visual Studio versions besides 2022, just change the path to vcvars64.bat.

  1. Install Visual Studio 2022.
  2. Use the Visual Studio Installer to install the optional Desktop Development with C++ workload. This contains native C/C++ build tools, including nmake.exe.
  3. Create a script in your home directory (C:\Users\UserName) ExVsCode.bat with the following (%1 is how you access the first command line argument, which will be the project directory):
cd %1
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat
code .
  1. When you want to work on an elixir project in VS Code, open a command prompt (CMD.exe), move to your home directory if you're not there already, and run ExVsCode.bat C:\Users\Username\PathToProject to open VS Code with all the build tools available to ElixirLS and the integrated terminal.

Credit to exqlite documentation for some of this.

Note: the original question may concern Cygwin, but many people will find this answer who are running elixir directly on Windows, and a closed question that doesn't mention Cygwin or WSL already points here.

Pirri answered 1/3, 2022 at 21:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.