ffi: error: implicit declaration of function 'ffi_prep_closure' on M1 macOS Big Sur
❯ rbenv install 2.4.0
Installing ruby-2.4.0...
WARNING: ruby-2.4.0 is past its end of life and is now unsupported.
It no longer receives bug fixes or critical security updates.
ruby-build: using readline from homebrew
BUILD FAILED (macOS 11.1 using ruby-build 20201210-10-g5de6d5f)
Inspect or clean up the working tree at /var/folders/mz/q1f7_y852v7__rt9f3lm0yd40000gn/T/ruby-build.20201229181439.24184.CZQlN7
Results logged to /var/folders/mz/q1f7_y852v7__rt9f3lm0yd40000gn/T/ruby-build.20201229181439.24184.log
Last 10 log lines:
compiling fiber.c
linking shared-object fiber.bundle
compiling closure.c
closure.c:263:14: error: implicit declaration of function 'ffi_prep_closure' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
result = ffi_prep_closure(pcl, cif, callback, (void *)self);
^
1 error generated.
make[2]: *** [closure.o] Error 1
make[1]: *** [ext/fiddle/all] Error 2
make: *** [build-ext] Error 2
logs
ruby-build.20201229181439.24184.log
install ruby 3.0.0 is ok
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 3
- Comments: 30
Commits related to this issue
- Fix ruby-build in M1 devices Suggested in https://github.com/ffi/ffi/issues/869#issuecomment-752123090 — committed to github/homebrew-bootstrap by sergiou87 3 years ago
- problems installing ffi bundle update ffi --bundler https://github.com/ffi/ffi/issues/869#issuecomment-810890178 brew info libffi - for macos (on M1) Signed-off-by: Kingdon Barrett <kingdon@weave.w... — committed to kingdonb/kubernetes-operator by kingdonb a year ago
I am also using RVM and in my situation, the following worked for me:
Step 1 Run in terminal: brew info libffi which will output the following:
For compilers to find libffi you may need to set: export LDFLAGS=“-L/opt/homebrew/opt/libffi/lib” export CPPFLAGS=“-I/opt/homebrew/opt/libffi/include”
For pkg-config to find libffi you may need to set: export PKG_CONFIG_PATH=“/opt/homebrew/opt/libffi/lib/pkgconfig”
Step 2 Run all 3 export commands in terminal to set the env variables.
Step 3 Finally, run the ruby installation command. In my case, it was: rvm install ruby-2.5.3
Hope it helps.
By the way, in a later date, I thought to record a video to demo how to do this. Here it goes: https://www.youtube.com/watch?v=M6Y6VIFHAL4
I was able to install other versions by passing
USE_FFI_CLOSURE_ALLOC
, like thisNew M1 macbook, this also worked for me!
In case it helps people using
ruby-install
, the following worked for that:Hi! I’m having this same problem using RVM, I tried all the top solutions but is not working, any ideas 🙏 ?
For rvm users: all 3 of these work-arounds worked for me:
(see rvm issue #5153)
I had the same problem on macOS 11.2.3 trying to install ruby 2.6.6 with RVM. @shakilearl’s solution helped with the installation problem. 2.6.6 works fine but when
rvm list
, I get:What does your
rvm list
log?Same problem on ventura 13.1, fixed like this:
would recommend trying the upvoted solutions from rvm/rvm#5047 or alternatively run
tested on Mac OSX Monterey v12.6.6
For anyone else that is not using the homebrew-bootstrap script that is reference above, I believe the line to execute should simply be
export RUBY_CFLAGS=-DUSE_FFI_CLOSURE_ALLOC
So for me, I have the M1 Mac and using rbenv and seeing this issue when trying to use rbenv install. When I export that flag, the issue was resolved and I can freely install ruby versions.
In the end, we decided to migrate everything to ruby 2.7.2 which seems like the earliest compatible version with M1s.
I have this as well, but so far everything seems to work as expected 🤷♂️
The same error happens to me. I can install
•
3.0.0
•2.7.2
But when I try to install
2.7.1
or2.6.6
I have the exact same issue. I’m using ffi1.14.2
.