You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

已安装C编译器,但bcrypt_elixir与Argon2仍无法正常工作求助

M1 Pro Mac使用Elixir/Phoenix时bcrypt_elixir/argon2加载失败问题

我用Macbook M1 Pro学习Elixir和Phoenix,尝试用bcrypt_elixir或argon2加密密码,但在iex -S mix中调用相关函数时,终端报错:

Bcrypt.Base.hash_password("hard to guess", Bcrypt.Base.gen_salt(12, true))
[error] Process #PID<0.610.0> raised an exception
** (RuntimeError) An error occurred when loading Bcrypt.
Make sure you have a C compiler and Erlang 20 installed.
If you are not using Erlang 20, either upgrade to Erlang 20 or
use version 0.12 of bcrypt_elixir.
See the Comeonin wiki for more information.

    (bcrypt_elixir 3.0.1) lib/bcrypt/base.ex:15: Bcrypt.Base.init/0
    (kernel 8.5.2) code_server.erl:1317: anonymous fn/1 in :code_server.handle_on_load/5
[warning] The on_load function for module Elixir.Bcrypt.Base returned:
{%RuntimeError{
   message: "An error occurred when loading Bcrypt.
Make sure you have a C compiler and Erlang 20 installed.
If you are not using Erlang 20, either upgrade to Erlang 20 or
use version 0.12 of bcrypt_elixir.
See the Comeonin wiki for more information.
"
 },
 [
   {Bcrypt.Base, :init, 0,
    [file: 'lib/bcrypt/base.ex', line: 15, error_info: %{...}]},
   {:code_server, :"handle_on_load/5-fun-0-", 1,
    [file: 'code_server.erl', line: 1317]}
 ]}

我已经验证C编译器和make已安装:

gcc --version
Apple clang version 13.1.6 (clang-1316.0.21.2.5)
Target: x86_64-apple-darwin22.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
❯ make --version
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for i386-apple-darwin11.3.0

同时尝试了bcrypt_elixir和argon2两个库,均出现类似错误。

我的Elixir和Erlang版本:

elixir -v
Erlang/OTP 25 [erts-13.1.3] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1] [jit] [dtrace]

Elixir 1.14.2 (compiled with Erlang/OTP 25)

解决方案

1. 切换到原生ARM终端

你的clang显示Target为x86_64-apple-darwin22.3.0,说明终端可能在Rosetta 2模式下运行,M1芯片需要原生ARM环境:

  • 打开Finder找到「终端.app」,右键选择「显示简介」,取消勾选「使用Rosetta打开」
  • 重启终端后,执行mix deps.compile bcrypt_elixir --force重新编译依赖

2. 安装完整Xcode命令行工具

执行以下命令安装/更新Xcode命令行工具:

xcode-select --install

安装完成后重启终端,清理并重新编译依赖:

mix deps.clean bcrypt_elixir
mix deps.get
mix deps.compile

3. 确保Erlang为ARM架构版本

如果用Homebrew安装Erlang,先卸载再重新安装原生ARM版本:

brew uninstall erlang
brew install erlang

如果用asdf管理版本,确保asdf是ARM版本,然后重新安装Erlang和Elixir:

asdf uninstall erlang 25.1.3
asdf uninstall elixir 1.14.2
asdf install erlang 25.1.3
asdf install elixir 1.14.2
asdf global erlang 25.1.3 elixir 1.14.2

之后清理并重新编译所有依赖:

mix deps.clean --all
mix deps.get
mix deps.compile

4. 强制指定ARM架构编译

如果上述方法无效,编译时直接指定ARM64架构:

ARCH=arm64 mix deps.compile bcrypt_elixir --force

内容的提问来源于stack exchange,提问作者Vagner Wentz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 19:02:50