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

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
psy-q
I’m trying to set up Emacs with elixir-ls via lsp-mode and credo via Flycheck. This should mostly be preconfigured as Flycheck picks up c...
New

Other Trending Topics Top

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
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews