`Unable to load crypto library` error on macOS after running some Homebrew commands

I commented on this Elixir lang GitHub issue:

I just observed this error today. I hadn’t seen it before. I installed both Erlang and Elixir via asdf, long before today. My specific error:

$ mix dialyzer
Compiling 1 file (.ex)
Finding suitable PLTs
Checking PLT...
[:asn1, :certifi, :compiler, :connection, :crontab, :crypto, :db_connection, :decimal, :ecto, :ecto_sql, :elixir, :hackney, :idna, :jason, :kernel, :logger, :metrics, :mimerl, :pane, :postgrex, :public_key, :scribe, :ssl, :ssl_verify_fun, :stdlib, :telemetry, :tzdata, :unicode_util_compat]

10:45:53.045 [error] Unable to load crypto library. Failed with error:
":load_failed, Failed to load NIF library: 'dlopen(/Users/kenny/.asdf/installs/erlang/22.2.1/lib/crypto-4.6.3/priv/lib/crypto.so, 2): Library not loaded: /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib
  Referenced from: /Users/kenny/.asdf/installs/erlang/22.2.1/lib/crypto-4.6.3/priv/lib/crypto.so
  Reason: image not found'"
OpenSSL might not be installed on this system.

10:45:53.050 [warn]  The on_load function for module crypto returned:
{:error, {:load_failed, 'Failed to load NIF library: \'dlopen(/Users/kenny/.asdf/installs/erlang/22.2.1/lib/crypto-4.6.3/priv/lib/crypto.so, 2): Library not loaded: /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib\n  Referenced from: /Users/kenny/.asdf/installs/erlang/22.2.1/lib/crypto-4.6.3/priv/lib/crypto.so\n  Reason: image not found\''}}

** (UndefinedFunctionError) function :crypto.hash/2 is undefined (module :crypto is not available)
    (crypto) :crypto.hash(:sha, <<131, 116, 0, 0, 0, 22, 100, 0, 7, 99, 101, 114, 116, 105, 102, 105, 104, 7, 100, 0, 3, 104, 101, 120, 100, 0, 7, 99, 101, 114, 116, 105, 102, 105, 109, 0, 0, 0, 5, 50, 46, 53, 46, 49, 109, 0, 0, 0, 64, 56, ...>>)
    lib/mix/tasks/dialyzer.ex:384: Mix.Tasks.Dialyzer.dependency_hash/0
    lib/mix/tasks/dialyzer.ex:247: Mix.Tasks.Dialyzer.check_plt/1
    lib/mix/tasks/dialyzer.ex:172: Mix.Tasks.Dialyzer.run/1
    (mix) lib/mix/task.ex:331: Mix.Task.run_task/3
    (mix) lib/mix/cli.ex:79: Mix.CLI.run_task/2

What I did do recently – yesterday – was install the Homebrew docutils package. I had to ‘overwrite links’ for some Python files/libraries – apparently, because of the impending Python 2 EOL, Homebrew is working on removing Python 2 dependencies.

I wonder if OpenSSL – the version I have installed – depends on those Python 2 libraries.

It seems now, based on replies to my comment in that same GitHub issue, the Homebrew inadvertently messed-up Erlang.

This existing post on this forum seems to cover my error:

In that post, several people confirmed that uninstalling and re-installing Erlang via asdf resolved the error. I’m going to try that now.

1 Like

Awesome! Let’s see what happens after a fresh reinstall.

But, you mentioned that it was Python that was crying, correct?

Where we discussed this before: https://github.com/elixir-lang/elixir/issues/5453

Sorry for not being clearer – I installed the Homebrew package docutils yesterday and that complained about some Python headers or similar files not being linked. I ran the brew link --overwrite ... command it suggested and that’s when this ‘fun’ started. I think I noticed another OpenSSL error for some other tool but didn’t look into it.

This morning is when I noticed these errors for Elixir/Erlang. The first such error was tzdata complaining about not being able to check for updates in an iex session. Then I noticed these errors more fully when I tried to run mix dialyzer (via Dialyxir).

Now, of course, even mix compile is complaining about OpenSSL being missing.

Uninstalling and re-installing Erlang via asdf did the trick!

1 Like

This trick has worked now for two separate Elixir projects, both of which were broken by these errors.