Cannot compile argon2 on MacOS

Hello.
I’m making a login function in my server. I’d like to use argon2 for hashing password. After installing {:argon2_elixir, "~> 2.0"} by mix deps.get, I have tried to compile the phoenix project.

==> argon2_elixir
mkdir -p priv
clang -02 -g -Wno-error=implicit-function-declaration -pthread -O3 -Wall -g -Iargon2/include -Iargon2/src -Ic_src -I"/Users/kunosouichirou/.asdf/installs/erlang/23.0.4/erts-11.0.4/include/" -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 priv/argon2_nif.so
clang: error: unknown argument: '-02'
make: *** [priv/argon2_nif.so] Error 1
could not compile dependency :argon2_elixir, "mix compile" failed. You can recompile this dependency with "mix deps.compile argon2_elixir", update it with "mix deps.update argon2_elixir" or clean it with "mix deps.clean argon2_elixir"
==> milk
** (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.

It stopped compiling at the process of argon2.
I guess it is a problem around my MacOS, but I have no clue to solve the problem.

Help me!

I use asdf for managing elixir and erlang version.

> asdf info
OS:
Darwin MacBook-Pro.local 19.6.0 Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64 x86_64

SHELL:
fish, version 3.1.2

ASDF VERSION:
v0.8.0-c6145d0

ASDF ENVIRONMENT VARIABLES:
ASDF_DIR=/Users/papillon/.asdf

ASDF INSTALLED PLUGINS:
elixir                       https://github.com/asdf-vm/asdf-elixir.git
erlang                       https://github.com/asdf-vm/asdf-erlang.git

> elixir -v   
Erlang/OTP 23 [erts-11.0.4] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe]

Elixir 1.9.4 (compiled with Erlang/OTP 20)

> erl +V 
Erlang (SMP,ASYNC_THREADS,HIPE) (BEAM) emulator version 11.0.4

It looks like you don’t have a compiler installed. You may have to install Xcode. What happens when you run "gcc --version"?

1 Like

i have installed xcode, gcc, make…

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
papillon@ ~/D/G/M/m/newman> gcc --version
gcc (Homebrew GCC 10.2.0) 10.2.0
Copyright (C) 2020 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.

I didn’t see this: clang: error: unknown argument: '-02'. It should be -O2 (the letter O, not the number 0).

1 Like

Is it an issue of argon2?

Based upon your message it would seem that the Makefile for argon 2 is incorrect in that it is specifying -02 when it should probably be -O2 as suggested by @ahamez

Two suggestions:

  1. File a bug report on argon2_elixir
  2. As a workaround, look in ./deps/argon2_elixir for a file called Makefile. In that file look for the line that includes clang -02 .... and change it to clang -O2 .... and then try mix deps.compile argon2_elixir
2 Likes

Thank you very much.
While I check the Makefile, I found I have set CFLAGS environment variament as -02 -g -Wno-error=implicit-function-declaration.

So I’ve deleted it and it worked!
thanks.