Skip to content

Could not open library 'sodium': dlopen(sodium, 5): image not found. (LoadError) on Apple Silicon M1 #880

@OleMchls

Description

@OleMchls

Hey there,

I'm trying to get rbnacl to function on my M1, but I am hitting the following error message:

ole@Oles-MBP-2 test % ruby -e "require 'rbnacl'" 
/Users/ole/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/rbnacl-7.1.1/lib/rbnacl/sodium/version.rb:10: warning: already initialized constant RbNaCl::Sodium::Version::MINIMUM_LIBSODIUM_VERSION
/Users/ole/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/rbnacl-7.1.1/lib/rbnacl/sodium/version.rb:10: warning: previous definition of MINIMUM_LIBSODIUM_VERSION was here
/Users/ole/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/rbnacl-7.1.1/lib/rbnacl/sodium/version.rb:11: warning: already initialized constant RbNaCl::Sodium::Version::MINIMUM_LIBSODIUM_VERSION_FOR_ARGON2
/Users/ole/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/rbnacl-7.1.1/lib/rbnacl/sodium/version.rb:11: warning: previous definition of MINIMUM_LIBSODIUM_VERSION_FOR_ARGON2 was here
/Users/ole/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/rbnacl-7.1.1/lib/rbnacl/sodium/version.rb:12: warning: already initialized constant RbNaCl::Sodium::Version::MINIMUM_LIBSODIUM_VERSION_FOR_ARGON2ID
/Users/ole/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/rbnacl-7.1.1/lib/rbnacl/sodium/version.rb:12: warning: previous definition of MINIMUM_LIBSODIUM_VERSION_FOR_ARGON2ID was here
Traceback (most recent call last):
	2: from -e:1:in `<main>'
	1: from /Users/ole/.asdf/installs/ruby/2.7.2/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
/Users/ole/.asdf/installs/ruby/2.7.2/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require': cannot load such file -- rbnacl (LoadError)
	15: from -e:1:in `<main>'
	14: from /Users/ole/.asdf/installs/ruby/2.7.2/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:156:in `require'
	13: from /Users/ole/.asdf/installs/ruby/2.7.2/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:168:in `rescue in require'
	12: from /Users/ole/.asdf/installs/ruby/2.7.2/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:168:in `require'
	11: from /Users/ole/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/rbnacl-7.1.1/lib/rbnacl.rb:12:in `<top (required)>'
	10: from /Users/ole/.asdf/installs/ruby/2.7.2/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
	 9: from /Users/ole/.asdf/installs/ruby/2.7.2/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
	 8: from /Users/ole/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/rbnacl-7.1.1/lib/rbnacl/sodium/version.rb:6:in `<top (required)>'
	 7: from /Users/ole/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/rbnacl-7.1.1/lib/rbnacl/sodium/version.rb:7:in `<module:RbNaCl>'
	 6: from /Users/ole/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/rbnacl-7.1.1/lib/rbnacl/sodium/version.rb:9:in `<module:Sodium>'
	 5: from /Users/ole/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/rbnacl-7.1.1/lib/rbnacl/sodium/version.rb:14:in `<module:Version>'
	 4: from /Users/ole/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/rbnacl-7.1.1/lib/rbnacl/sodium/version.rb:14:in `extend'
	 3: from /Users/ole/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/rbnacl-7.1.1/lib/rbnacl/sodium.rb:11:in `extended'
	 2: from /Users/ole/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/ffi-1.14.2/lib/ffi/library.rb:99:in `ffi_lib'
	 1: from /Users/ole/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/ffi-1.14.2/lib/ffi/library.rb:99:in `map'
/Users/ole/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/ffi-1.14.2/lib/ffi/library.rb:145:in `block in ffi_lib': Could not open library 'sodium': dlopen(sodium, 5): image not found. (LoadError)
Could not open library 'libsodium.dylib': dlopen(libsodium.dylib, 5): image not found.
Could not open library 'libsodium.so.18': dlopen(libsodium.so.18, 5): image not found.
Could not open library 'libsodium.so.18.dylib': dlopen(libsodium.so.18.dylib, 5): image not found.
Could not open library 'libsodium.so.23': dlopen(libsodium.so.23, 5): image not found.
Could not open library 'libsodium.so.23.dylib': dlopen(libsodium.so.23.dylib, 5): image not found

While at first, this looks like I don't have libsodium installed, I want to point out that I do have it installed via brew.

ole@Oles-MBP-2 test % brew test libsodium          
==> Testing libsodium
==> /usr/bin/clang test.c -I/opt/homebrew/Cellar/libsodium/1.0.18_1/include -L/opt/homebrew/Cellar/libsodium/1.0.18_1/lib -lsodium -o test
==> ./test

But it seems it just does not pick it up. I've started my investigations over here before: RubyCrypto/rbnacl#216

I use asdf which uses ruby-build to build my ruby:

ole@Oles-MBP-2 test % ruby -v                      
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [arm64-darwin20]

Any pointers or workarounds would be appreciated 👏

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions