`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.

2 Likes

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

1 Like

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!

3 Likes

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

1 Like

Hi! I seem to have run into the same issue, however, the uninstalling and reinstalling Erlang with asdf does not resolve it, even if I specify the path to my version of openssl:

export KERL_CONFIGURE_OPTIONS="--with-ssl=$(brew --prefix openssl)"

Like @kenny-evitt I set up Elixir and Erlang long ago using asdf and it was working great until yesterday. The only change I made before things stopped working that seems like it could have caused this was installing emacs using brew. Now running any mix task an almost identical error to Kenny’s:

17:24:54.491 [error] Unable to load crypto library. Failed with error:
":load_failed, Failed to load NIF library: 'dlopen(/usr/local/Cellar/erlang/21.2.4/lib/erlang/lib/crypto-4.4/priv/lib/crypto.so, 2): Library not loaded: /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib
  Referenced from: /usr/local/Cellar/erlang/21.2.4/lib/erlang/lib/crypto-4.4/priv/lib/crypto.so
  Reason: image not found'"
OpenSSL might not be installed on this system.

17:24:54.492 [warn]  The on_load function for module crypto returned:
{:error, {:load_failed, 'Failed to load NIF library: \'dlopen(/usr/local/Cellar/erlang/21.2.4/lib/erlang/lib/crypto-4.4/priv/lib/crypto.so, 2): Library not loaded: /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib\n  Referenced from: /usr/local/Cellar/erlang/21.2.4/lib/erlang/lib/crypto-4.4/priv/lib/crypto.so\n  Reason: image not found\''}}

It seems like --with-ssl isn’t having any effect. I’m pretty sure that the brew update/install I did deleted openssl 1.0, I assume to force the upgrade to 1.1. I only have v1.1 installed.

I have tried using Kerl directly and several different versions of Erlang & Elixir with ‘–with-ssl’ specified. I keep getting the same error looking for libcrypto.1.0.0.dylib instead of libcrypto.1.1.0.dylib. I am on OS X Catalina (10.15.4) and XCode 11.4.1. I upgraded my XCode while trying to fix this since I was on a old version and getting warnings.

Anybody have any ideas why ‘–with-ssl’ isn’t working for specifying the version of OpenSSL? Am I missing something? It doesn’t seem like it is a linking problem (although brew does give me the same warning about refusing to link openssl@1.1).

I’ve also tried messing around with CFLAGS & tried setting LDFLAGS & CPPFLAGS but haven’t had any luck.

1 Like

I was able to install using pure brew without a problem, so I am out of the woods for now (with versions 1.10.3 & 22.3.4).

Any insight that helps get asdf working again would still be appreciated. Without asdf I am likely to run into version issues down the road when switching between apps.

1 Like

I started getting this error from last week.
I am running the app in google cloud run and it was working fine until last week.
But now i am getting the error

 [load_failed,"Failed to load NIF library /app/lib/crypto-4.6.5.4/priv/lib/crypto: 'libcrypto.so.1.1: cannot open shared object file: No such file or directory'","OpenSSL might not be installed on this system.\n"]
"Unable to load crypto library. Failed with error:~n\"~p, ~s\"~n~s"

I am using docker image elixir-1.10.4-slim.
I can see there was no update made from last 3 years but the debian:buster image that erlang:22-slim uses was updated last week.
I tried changing the different versions of the elixir image but all of them are getting the same error.

Please help me out here.
Thanks in advance