简体   繁体   English

如何修复 Windows 上的“无法编译依赖项:bcrypt_elixir”错误?

[英]How to fix "could not compile dependency :bcrypt_elixir" error on Windows?

I'm on Windows and I am trying to install the bcrypt_elixir module.我在 Windows 上,我正在尝试安装 bcrypt_elixir 模块。

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:这是错误的终端屏幕截图:

错误

Here is my deps function from mix.exs :这是我来自depsmix.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

I faced same problem during distillery setup with my elixir project.我在使用 Elixir 项目进行酿酒厂设置时遇到了同样的问题。

Installing package resolve issue as shown below.安装包解决问题,如下所示。

I found bcrypt_elixir need to install make and build-essential from Elixir Forum.我发现 bcrypt_elixir 需要从 Elixir 论坛安装 make 和 build-essential。

platform:- ubuntu平台:- ubuntu

$ sudo apt install make $ sudo apt install make

$ sudo apt-get install build-essential $ sudo apt-get install build-essential

bcrypt_elixir uses Windows' NMake (cf. bcrypt_elixir's Makefile.win ). bcrypt_elixir 使用 Windows 的 NMake(参见 bcrypt_elixir 的Makefile.win )。

It seems like you don't have NMake installed.您似乎没有安装 NMake。

From NMake's documentation :NMake 的文档

NMAKE is included when you install Visual Studio or the Visual C++ command-line build tools. NMAKE 在您安装 Visual Studio 或 Visual C++ 命令行生成工具时包含在内。 It's not available separately.它不能单独使用。

So you need to download Visual Studio in order to get NMake.因此,您需要下载 Visual Studio才能获得 NMake。 Then you should be able to compile bcrypt_elixir.然后你应该能够编译 bcrypt_elixir。

If you already have NMake , make sure nmake.exe is located under a directory from your path .如果您已经有nmake.exe ,请确保nmake.exe位于您的路径中的目录下。

对于 Visual Studio 2019 (VS2019):

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

In windows 10, you must add NMAKE to your path在 Windows 10 中,您必须将 NMAKE 添加到您的路径中在此处输入图片说明

After that you can run mix deps.compile until see message like this:之后你可以运行 mix deps.compile 直到看到这样的消息: 在此处输入图片说明

After that you must run cmd as suggest from nmake:之后,您必须按照 nmake 的建议运行 cmd:

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.在 cmd 上运行此命令并正常运行mix deps.compile deps.compile 。

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.实际上仔细看看这个,因为你正在运行 Cygwin 并试图在 Cygwin 下构建 bcrypt, nmake甚至没有进入这个问题。 You need to install make into Cygwin.您需要将make安装到 Cygwin 中。 Re-run the cygwin installer, select the Devel category and then under Devel look for make.重新运行 cygwin 安装程序,选择Devel类别,然后在 Devel 下查找 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. a.) 停止尝试在 Cygwin 提示符下构建所有内容——如果 bcrypt_elixir 检测到它在 Windows 上,它将寻找 nmake 而 nmake 不是 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.你没有指定你如何寻找 nmake 但如果我是你,我会从C:\\Program Files (x86)目录中尝试这个。

dir /s nmake.exe

Mind you run that from a Windows cmd prompt--it won't work from the Cygwin shell!请注意,您是从 Windows cmd 提示符运行它的——它在 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). b.) 以某种方式将 bcrypt_elixir 设置为认为它在 Linux 上,因此它会查找 make(与 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.基本上我认为最简单的答案是尝试从普通的 Windows cmd 提示符运行 mix phx.server 然后从那里开始。 Or if you need Linux, then install virtual box and put a Linux VM on the machine and proceed that way.或者,如果您需要 Linux,则安装 virtual box 并在机器上放置一个 Linux VM,然后继续。

I found that, running on Windows, it was the latest version of erlang OTP, version 21, that was causing the problem.我发现在 Windows 上运行的是最新版本的 erlang OTP,版本 21,导致了问题。 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我卸载了这个版本并使用了 20 版本(它安装了 erlang 9.3 和最新版本的 Elixir,然后在编译时查找这个版本)然后 bcrypt_elixir 编译

This answer is for anyone running elixir directly on Windows , and using VS Code with the ElixirLS extension.这个答案适用于直接在 Windows 上运行 elixir 并使用带有 ElixirLS 扩展的 VS Code 的任何人。 These instructions should work for other Visual Studio versions besides 2022, just change the path to vcvars64.bat.这些说明应该适用于 2022 以外的其他 Visual Studio 版本,只需将路径更改为 vcvars64.bat。

  1. Install Visual Studio 2022.安装 Visual Studio 2022。
  2. Use the Visual Studio Installer to install the optional Desktop Development with C++ workload.使用 Visual Studio 安装程序安装Desktop Development with C++ This contains native C/C++ build tools, including nmake.exe.这包含本机 C/C++ 构建工具,包括 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):使用以下内容在您的主目录 (C:\Users\UserName) ExVsCode.bat 中创建一个脚本( %1是您访问第一个命令行参数的方式,它将是项目目录):
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.当您想在 VS Code 中处理 elixir 项目时,打开命令提示符 (CMD.exe),如果您不在主目录,则移至主目录,然后运行ExVsCode.bat C:\Users\Username\PathToProject以使用 ElixirLS 和集成终端可用的所有构建工具打开 VS Code。

Credit to exqlite documentation for some of this.其中一些归功于 exqlite 文档

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.注意:原始问题可能与Cygwin有关,但是很多人会直接在Windows上运行elixir找到这个答案,并且没有提到Cygwin或WSL的封闭问题已经指向这里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM