Joshua

Joshua

Using macOS Monterey 12.1 with M1 Pro.

Elixir version:

$ elixir --version
Erlang/OTP 24 [erts-12.2] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1] [dtrace]

Elixir 1.13.1 (compiled with Erlang/OTP 24)

Argon2 just doesn’t seem to want to compile.
Whenever I try to use Argon2, this happens:

iex(1)> Argon2.Base.init()
** (UndefinedFunctionError) function Argon2.Base.init/0 is undefined (module Argon2.Base is not available)
    (argon2_elixir 2.4.0) Argon2.Base.init()
iex(1)> 
20:37:46.896 [error] Process #PID<0.436.0> raised an exception
** (RuntimeError) An error occurred when loading Argon2.
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 bcrypt_elixir (version 0.12) or pbkdf2_elixir.
See the Comeonin wiki for more information.

    (argon2_elixir 2.4.0) lib/argon2/base.ex:19: Argon2.Base.init/0
    (kernel 8.2) code_server.erl:1317: anonymous fn/1 in :code_server.handle_on_load/5
 
20:37:46.903 [error] Process #PID<0.438.0> raised an exception
** (RuntimeError) An error occurred when loading Argon2.
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 bcrypt_elixir (version 0.12) or pbkdf2_elixir.
See the Comeonin wiki for more information.

    (argon2_elixir 2.4.0) lib/argon2/base.ex:19: Argon2.Base.init/0
    (kernel 8.2) code_server.erl:1317: anonymous fn/1 in :code_server.handle_on_load/5
 
20:37:46.897 [warning] The on_load function for module Elixir.Argon2.Base returned:
{%RuntimeError{
   message: "An error occurred when loading Argon2.\nMake sure you have a C compiler and Erlang 20 installed.\nIf you are not using Erlang 20, either upgrade to Erlang 20 or\nuse bcrypt_elixir (version 0.12) or pbkdf2_elixir.\nSee the Comeonin wiki for more information.\n"
 },
 [
   {Argon2.Base, :init, 0,
    [file: 'lib/argon2/base.ex', line: 19, error_info: %{...}]},
   {:code_server, :"-handle_on_load/5-fun-0-", 1,
    [file: 'code_server.erl', line: 1317]}
 ]}

 
20:37:46.908 [warning] The on_load function for module Elixir.Argon2.Base returned:
{%RuntimeError{
   message: "An error occurred when loading Argon2.\nMake sure you have a C compiler and Erlang 20 installed.\nIf you are not using Erlang 20, either upgrade to Erlang 20 or\nuse bcrypt_elixir (version 0.12) or pbkdf2_elixir.\nSee the Comeonin wiki for more information.\n"
 },
 [
   {Argon2.Base, :init, 0,
    [file: 'lib/argon2/base.ex', line: 19, error_info: %{...}]},
   {:code_server, :"-handle_on_load/5-fun-0-", 1,
    [file: 'code_server.erl', line: 1317]}
 ]}

I’ve already tried cleaning all dependencies, reinstalling them. I checked and yes I do have a C compiler. I’m starting to worry that this won’t work on Apple Silicon.

Any other suggestions? Thanks

Showing Posts 1 to 10

al2o3cr

al2o3cr

The error suggests that it’s not finding the artifact it expects, but if that failed to compile it should show up in the output of mix deps.compile --force. Weird. :thinking:

I don’t have an M1 to test with, but one way I imagine this could happen is if the dependency compilation and the iex were mismatched - one on Rosetta and the other not.

Joshua

Joshua OP

Did some digging around, found something interesting.
Firstly, I cloned the argon2_elixir GitHub onto my M1 Pro machine.
Fetched the dependencies, and ran make.

$ make        
mix compile
==> earmark_parser
Compiling 1 file (.yrl)
Compiling 2 files (.xrl)
Compiling 3 files (.erl)
Compiling 32 files (.ex)
Generated earmark_parser app
==> erlex
Compiling 1 file (.yrl)
src/parser.yrl: Warning: conflicts: 27 shift/reduce, 0 reduce/reduce
Compiling 1 file (.xrl)
Compiling 2 files (.erl)
Compiling 1 file (.ex)
Generated erlex app
==> nimble_parsec
Compiling 4 files (.ex)
Generated nimble_parsec app
==> makeup
Compiling 44 files (.ex)
Generated makeup app
==> comeonin
Compiling 4 files (.ex)
Generated comeonin app
==> dialyxir
Compiling 59 files (.ex)
warning: Mix.Project.compile/1 is deprecated. Use Mix.Task.run("compile", args) instead
  lib/mix/tasks/dialyzer.ex:164: Mix.Tasks.Dialyzer.run/1

warning: Mix.Project.compile/1 is deprecated. Use Mix.Task.run("compile", args) instead
  lib/dialyxir/project.ex:47: Dialyxir.Project.cons_apps/0

Generated dialyxir app
==> elixir_make
Compiling 1 file (.ex)
Generated elixir_make app
==> makeup_elixir
Compiling 6 files (.ex)
Generated makeup_elixir app
==> ex_doc
Compiling 22 files (.ex)
Generated ex_doc app
==> argon2_elixir
mkdir -p /Users/joshuazacek/Desktop/argon2_elixir/_build/dev/lib/argon2_elixir/priv
make[1]: *** No rule to make target `argon2/src/argon2.c', needed by `/Users/joshuazacek/Desktop/argon2_elixir/_build/dev/lib/argon2_elixir/priv/argon2_nif.so'.  Stop.
** (Mix) Could not compile with "make" (exit status: 2).
You need to have gcc and make installed. Try running the
commands "gcc --version" and / or "make --version". If these programs
are not installed, you will be prompted to install them.

make: *** [calling_from_make] Error 1
$ gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 13.0.0 (clang-1300.0.29.30)
Target: arm64-apple-darwin21.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/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

I’m not a C developer by any means, so I’m just relying on Stack Overflow, but it seems like some file is missing for some reason.

kip

kip

ex_cldr Core Team

I did a basic installation as you did but with different results!

kip@Kips-MacBook-Pro argon % iex -S mix
Erlang/OTP 24 [erts-12.1.5] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1] [dtrace]

==> comeonin
Compiling 4 files (.ex)
Generated comeonin app
==> elixir_make
Compiling 1 file (.ex)
Generated elixir_make app
==> argon2_elixir
mkdir -p /Users/kip/Development/argon/_build/dev/lib/argon2_elixir/priv
cc -O2 -g -fno-stack-check -pthread -Wall -Wno-format-truncation -I"/Users/kip/.asdf/installs/erlang/24.1.7/erts-12.1.5/include" -Iargon2/include -Iargon2/src -Ic_src -dynamiclib -undefined dynamic_lookup  argon2/src/argon2.c argon2/src/core.c argon2/src/blake2/blake2b.c argon2/src/thread.c argon2/src/encoding.c argon2/src/ref.c c_src/argon2_nif.c -o /Users/kip/Development/argon/_build/dev/lib/argon2_elixir/priv/argon2_nif.so
warning: unknown warning option '-Wno-format-truncation' [-Wunknown-warning-option]
1 warning generated.
warning: unknown warning option '-Wno-format-truncation' [-Wunknown-warning-option]
1 warning generated.
warning: unknown warning option '-Wno-format-truncation' [-Wunknown-warning-option]
1 warning generated.
warning: unknown warning option '-Wno-format-truncation' [-Wunknown-warning-option]
1 warning generated.
warning: unknown warning option '-Wno-format-truncation' [-Wunknown-warning-option]
1 warning generated.
warning: unknown warning option '-Wno-format-truncation' [-Wunknown-warning-option]
1 warning generated.
warning: unknown warning option '-Wno-format-truncation' [-Wunknown-warning-option]
1 warning generated.
Compiling 3 files (.ex)
Generated argon2_elixir app
==> argon
Compiling 1 file (.ex)
Generated argon app
Interactive Elixir (1.13.1) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> Argon2.Base.init()
** (RuntimeError) An error occurred when loading Argon2.
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 bcrypt_elixir (version 0.12) or pbkdf2_elixir.
See the Comeonin wiki for more information.

    (argon2_elixir 2.4.0) lib/argon2/base.ex:19: Argon2.Base.init/0
iex(1)> 

My versions of gcc and make as the same as yours. I think I have the right binary format (all ARM64):

kip@Kips-MacBook-Pro argon % file ./_build/dev/lib/argon2_elixir/priv/argon2_nif.so
./_build/dev/lib/argon2_elixir/priv/argon2_nif.so: Mach-O 64-bit dynamically linked shared library arm64

Not sure what to try next, I’m well out of my depth now…

Joshua

Joshua OP

Okay, so I took the dependency straight out of the /deps folder and use that instead. Got the same results as you.

So, I dug a little deeper and went looking around to see where the error was being thrown. Turns out it came down to this function:

  defp load_nif do
    path = :filename.join(:code.priv_dir(:argon2_elixir), 'argon2_nif')
    :erlang.load_nif(path, 0)
  end

So, I ran this code directly in the IEX shell, and this happened:

iex(2)> :erlang.load_nif(:filename.join(:code.priv_dir(:argon2_elixir), 'argon2_nif'), 0)
{:error,
 {:bad_lib,
  'load_nif/2 must be explicitly called from the NIF module. It cannot be called through apply/3.'}} 

Looks like Erlang isn’t happy. Any good Erlang/C people that can parse this message?

kip

kip

ex_cldr Core Team

That message basically means what it says: you can’t call :erlang.load_nif/2 from anywhere except within a nif module. So unfortunately we’re no further forward at this point.

Joshua

Joshua OP

Sorry, I ran this in the IEX shell :man_facepalming:

This time, I actually ran it in the module, and got this instead:

{:error,
 {:reload, 'NIF library already loaded (reload disallowed since OTP 20).'}}
Joshua

Joshua OP

I finally found out what it was. As someone suggested earlier in the thread, x86_64 binaries where being compiled instead of arm64 ones. Not sure why, but I found the fix.

  1. Run gcc --version, and copy the target (in my case, arm64-apple-darwin21.2.0)
$ gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 13.0.0 (clang-1300.0.29.30)
Target: arm64-apple-darwin21.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
  1. Open /deps/argon2_elixir/Makefile and add this line: CFLAGS += -target (your target)
  2. Open mix.exs and change {:argon2_elixir: "~> 2.0"} to {:argon2_elixir, path: "deps/argon2_elixir"}
zac

zac

So… 2023 and this still appears to be a problem? Has anyone come up with a more elegant solution than hacking the deps/argon2_elixir/Makefile?

al2o3cr

al2o3cr

The original poster included more detail about what happened in their update on the corresponding issue:

https://github.com/riverrun/argon2_elixir/issues/52

It turns out than an IDE extension was compiling the modules automatically, and it was running under Rosetta.

zac

zac

Ahhh. Ok, don’t have Rosetta installed here… found this running down related posts about M1 and argon2 failed compile issues. (None of which followed up w/ solutions…)

However… finally figured out what broke it. There’s a space in my project pathname. While that shouldn’t be a problem looks like it is – moved my project dir so no space, and getting a good compile.

So. Don’t use spaces. :confused:

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews