larskanis/libusb

undefined symbol: ffi_prep_cif_machdep on Raspberry Pi

rgaufman opened this issue · 3 comments

I did bundle package --all on my Mac 13.2.1, this worked correctly.

When I run bundle install on the Raspberry Pi however, using the local vendor cache, I get this:

$ gem install libusb
Building native extensions. This could take a while...
ERROR:  Error installing libusb:
	ERROR: Failed to build gem native extension.

    current directory: /usr/local/lib/ruby/gems/3.1.0/gems/libusb-0.6.4/ext
/usr/local/bin/ruby -I /usr/local/lib/ruby/3.1.0 -r ./siteconf20230322-10162-mu22sz.rb extconf.rb
Ignoring libusb-0.6.4 because its extensions are not built. Try: gem pristine libusb --version 0.6.4
/usr/local/bin/ruby: symbol lookup error: /usr/local/lib/ruby/gems/3.1.0/gems/ffi-1.15.5/lib/ffi_c.so: undefined symbol: ffi_prep_cif_machdep

extconf failed, exit code 127

Gem files will remain installed in /usr/local/lib/ruby/gems/3.1.0/gems/libusb-0.6.4 for inspection.
Results logged to /usr/local/lib/ruby/gems/3.1.0/extensions/armv7l-linux-eabihf/3.1.0-static/libusb-0.6.4/gem_make.out

This used to work until recently and I can't recall any changes at all.

Strangely, if I reinstall ffi, it works:

$ gem install ffi
Building native extensions. This could take a while...
Successfully installed ffi-1.15.5
Parsing documentation for ffi-1.15.5
Done installing documentation for ffi after 5 seconds
1 gem installed
$ gem install libusb
Building native extensions. This could take a while...
Successfully installed libusb-0.6.4
Parsing documentation for libusb-0.6.4
Done installing documentation for libusb after 1 seconds
1 gem installed

Any ideas?

I now have another Raspberry Pi where re-installing ffi does not help:

$ rm -R /usr/local/lib/ruby/gems/3.1.0/gems/ffi-1.15.5
$ gem install libusb
Fetching ffi-1.15.5.gem
Building native extensions. This could take a while...
Successfully installed ffi-1.15.5
Building native extensions. This could take a while...
ERROR:  Error installing libusb:
	ERROR: Failed to build gem native extension.

    current directory: /usr/local/lib/ruby/gems/3.1.0/gems/libusb-0.6.4/ext
/usr/local/bin/ruby -I /usr/local/lib/ruby/3.1.0 -r ./siteconf20230327-26079-gt026i.rb extconf.rb
/usr/local/bin/ruby: symbol lookup error: /usr/local/lib/ruby/gems/3.1.0/gems/ffi-1.15.5/lib/ffi_c.so: undefined symbol: ffi_prep_cif_machdep

extconf failed, exit code 127

Gem files will remain installed in /usr/local/lib/ruby/gems/3.1.0/gems/libusb-0.6.4 for inspection.
Results logged to /usr/local/lib/ruby/gems/3.1.0/extensions/armv7l-linux-eabihf/3.1.0-static/libusb-0.6.4/gem_make.out
$ ruby --version
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [armv7l-linux-eabihf]
$ gem -v
3.3.7
$ lsb_release -a
No LSB modules are available.
Distributor ID:	Raspbian
Description:	Raspbian GNU/Linux 11 (bullseye)
Release:	11
Codename:	bullseye

Any ideas?

Not sure why this is happening, but this appears to work as a workaround:

gem install ffi -- --enable-system-libffi

There are new ffi versions released, which could have fixed this issue. There's also a ffi prerelease with binary gems for arm-linux. It can be installed per:

gem inst ffi --pre