akihikodaki / cld3-ruby

cld3-ruby is an interface of Compact Language Detector v3 (CLD3) for Ruby.
Apache License 2.0
78 stars 22 forks source link

symbol not found in flat namespace '__ZN6google8protobuf8internal16InternalMetadataD1Ev' #36

Closed delphaber closed 2 years ago

delphaber commented 2 years ago

Hello :)

thanks for this gem!

After an upgrade to protobuf, rails console raises this error

/Users/faber/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/ffi-1.15.5/lib/ffi/library.rb:145:in `block in ffi_lib': Could not open library '/Users/faber/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/cld3-3.4.4/lib/cld3/../../ext/cld3/libcld3.bundle': dlopen(/Users/faber/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/cld3-3.4.4/lib/cld3/../../ext/cld3/libcld3.bundle, 0x0005): symbol not found in flat namespace '__ZN6google8protobuf8internal16InternalMetadataD1Ev' (LoadError)
    from /Users/faber/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/ffi-1.15.5/lib/ffi/library.rb:99:in `map'
    from /Users/faber/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/ffi-1.15.5/lib/ffi/library.rb:99:in `ffi_lib'
    from /Users/faber/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/cld3-3.4.4/lib/cld3/unstable.rb:22:in `<module:Unstable>'
    from /Users/faber/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/cld3-3.4.4/lib/cld3/unstable.rb:19:in `<module:CLD3>'
    from /Users/faber/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/cld3-3.4.4/lib/cld3/unstable.rb:18:in `<main>'
    from /Users/faber/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
    from /Users/faber/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
    from /Users/faber/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/activesupport-6.1.6/lib/active_support/dependencies.rb:332:in `block in require'
    from /Users/faber/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/activesupport-6.1.6/lib/active_support/dependencies.rb:299:in `load_dependency'
    from /Users/faber/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/activesupport-6.1.6/lib/active_support/dependencies.rb:332:in `require'
    from /Users/faber/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/cld3-3.4.4/lib/cld3.rb:22:in `<main>'
    from /Users/faber/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
    from /Users/faber/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
    from /Users/faber/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.3.10/lib/bundler/runtime.rb:60:in `block (2 levels) in require'
    from /Users/faber/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.3.10/lib/bundler/runtime.rb:55:in `each'
    from /Users/faber/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.3.10/lib/bundler/runtime.rb:55:in `block in require'
    from /Users/faber/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.3.10/lib/bundler/runtime.rb:44:in `each'
    from /Users/faber/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.3.10/lib/bundler/runtime.rb:44:in `require'

I'm using these versions at the moment:

$ protoc --version
libprotoc 3.20.1

$ bundle show cld3
cld3-3.4.4

$ ruby -v
ruby 2.7.6p219 (2022-04-12 revision c9c2245c0a) [x86_64-darwin21]

I've tried to reinstall cld3 with bundle pristine, to delete tmp/cache/bootsnap but got the same error.

Any suggestion?

Thank you!

akihikodaki commented 2 years ago

Reinstalling cld3 is a good call, but it is to rebuild the extension rather than to clear the Bootsnap cache. It is common that updating protocol buffer breaks the ABI compatibility, requiring the extension to be rebuilt for the new ABI.

I suggest to check if /Users/faber/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/cld3-3.4.4/lib/cld3/../../ext/cld3/libcld3.bundle is rebuilt after bundle pristine. Also you may check the log of Bundler and RubyGems.

To reinstall only cld3, you may run: bundle exec gem pristine cld3

delphaber commented 2 years ago

hi @akihikodaki thanks for the fast reply!

I've reinstalled protobuf@3 with homebrew (protobuf recipe is pointing to version 21, so I had to use protobuf@3, which points to version 3.20.1)

$ brew reinstall protobuf@3
$ brew link protobuf@3 # to make sure compiler can find the library

I've tried to run gem pristine cld3 to make sure the bundle is compiled again

[09:16]
 ↳ $ gem pristine cld3
Restoring gems to pristine condition...
Building native extensions. This could take a while...
Restored cld3-3.4.1
[09:16]
 ↳ $ ls -la /Users/faber/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/cld3-3.4.1/lib/../ext/cld3/libcld3.bundle
-rwxr-xr-x  1 faber  staff   837K Jul 19 09:16 /Users/faber/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/cld3-3.4.1/lib/../ext/cld3/libcld3.bundle*
[09:17]
 ↳ $ gem pristine cld3
Restoring gems to pristine condition...
Building native extensions. This could take a while...
Restored cld3-3.4.1
[09:17]
 ↳ $ ls -la /Users/faber/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/cld3-3.4.1/lib/../ext/cld3/libcld3.bundle
-rwxr-xr-x  1 faber  staff   837K Jul 19 09:17 /Users/faber/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/cld3-3.4.1/lib/../ext/cld3/libcld3.bundle*

You can see the timestamps from ls -la changing.

Unfortunately I still get symbol not found in flat namespace '__ZN6google8protobuf8internal16InternalMetadataD1Ev' when running rails c (or any other rails/rake command that load the bundle)

I've also cleared my bootsnap cache, I've stropped spring and I've reboot my mac 😅

Update

I've tried with cld3 v3.4.4, but I've got the same result

RubysDad commented 2 years ago

I'm running into this same issue as well.

akihikodaki commented 2 years ago

I have just published version 3.5.0, removing protocol buffers dependency! It has always been a problem since the release of this gem. Hopefully it eliminates this class of problems once for all...

delphaber commented 2 years ago

thank you @akihikodaki ! I'm gonna try this tomorrow!

RubysDad commented 2 years ago

Upgrading to 3.5.0 worked for me. Thank you @akihikodaki

delphaber commented 2 years ago

Thanks it works for me too!