dyld: Symbol not found: _ffi_prep_closure_loc (on Mac)
Asked Answered
G

4

9

I did a regular flutter run on my Mac, targeting my iPhone simulator today and got these errors.

Error output from CocoaPods:
↳
    dyld: lazy symbol binding failed: Symbol not found: _ffi_prep_closure_loc
      Referenced from: /Users/toure/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/ffi-1.13.1/lib/ffi_c.bundle
      Expected in: /usr/lib/libffi.dylib

    dyld: Symbol not found: _ffi_prep_closure_loc
      Referenced from: /Users/toure/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/ffi-1.13.1/lib/ffi_c.bundle
      Expected in: /usr/lib/libffi.dylib

How do you solve the dyld: Symbol not found: _ffi_prep_closure_loc error?

Gilthead answered 5/8, 2020 at 14:45 Comment(0)
G
18

I found a fix buried in a github issue.

Running this on my Mac solved the problem.

gem uninstall ffi
brew reinstall libffi
export LDFLAGS="-L/usr/local/opt/libffi/lib"
export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig"
gem install ffi

I decided to share this since the error in the title of the issue is different from the one that I got. Hope this can save someone some time.

Gilthead answered 5/8, 2020 at 14:45 Comment(1)
Wow! After trying a lot of things: reinstall FFI, Ruby… nothing fixed the issue. Your solution worked perfectly. Thanks! 😊Brigadier
C
6

I was able to resolve this by reinstalling the utility with this flag:

gem install ffi -- --disable-system-libffi

Turns out ffi-1.13.1 is using ffi_prep_closure_loc() and system-libffi for Mac doesn’t have that function.

See ffi issue #791 for more.

Constrictor answered 29/11, 2020 at 21:10 Comment(0)
D
2

Toure's solution, but for newer Homebrew installs:

gem uninstall ffi
brew reinstall libffi
export LDFLAGS="-L/opt/homebrew/opt/libffi/lib"
export PKG_CONFIG_PATH="/opt/homebrew/opt/libffi/lib/pkgconfig"
gem install ffi
Dioecious answered 16/5, 2022 at 9:18 Comment(0)
K
0

for M1 v13 Ventura, you should be able to install older version with:

gem install ffi -v '1.11.1' -- --enable-libffi-alloc ref. https://github.com/ffi/ffi/issues/800#issuecomment-748434595

but problem was when running after rake db:create got again same error. So only what did help, like mentioned in reference:

gem install ffi -v '1.14.0'
And changing also to this version in gemfile.lock
Killebrew answered 30/10, 2022 at 17:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.