ffi: Failed to build gem native extension on macOS High Sierra
Getting this error when installing jekyll
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-darwin16]
Bundler version 1.16.6 (2018-10-05 commit f66c33467)
xcode-select --install
is already updatedgcc -v
:
Configured with: --prefix=/Users/me/Downloads/Xcode 10.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 10.0.0 (clang-1000.11.45.2)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /Users/me/Downloads/Xcode 10.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
➜ website git:(master) gem install jekyll
Building native extensions. This could take a while...
ERROR: Error installing jekyll:
ERROR: Failed to build gem native extension.
current directory: /Users/me/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/ffi-1.9.25/ext/ffi_c
/Users/me/.rbenv/versions/2.4.2/bin/ruby -r ./siteconf20181022-70130-1j1h50c.rb extconf.rb
checking for ffi.h... no
checking for ffi.h in /usr/local/include,/usr/include/ffi... yes
checking for ffi_call() in -lffi... yes
checking for ffi_closure_alloc()... no
checking for ffi_raw_call()... no
checking for shlwapi.h... no
checking for ruby/thread.h... yes
checking for rb_thread_blocking_region()... no
checking for rb_thread_call_with_gvl()... yes
checking for rb_thread_call_without_gvl()... yes
creating extconf.h
creating Makefile
current directory: /Users/me/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/ffi-1.9.25/ext/ffi_c
make "DESTDIR=" clean
current directory: /Users/me/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/ffi-1.9.25/ext/ffi_c
make "DESTDIR="
Configuring libffi
clang: error: unsupported option '-print-multi-os-directory'
clang: error: no input files
cd "/Users/me/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/ffi-1.9.25/ext/ffi_c/libffi-x86_64-darwin16" && /Users/me/Downloads/Xcode 10.app/Contents/Developer/usr/bin/make
/bin/sh: /Users/me/Downloads/Xcode: No such file or directory
make: *** ["/Users/me/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/ffi-1.9.25/ext/ffi_c/libffi-x86_64-darwin16"/.libs/libffi_convenience.a] Error 127
make failed, exit code 2
Gem files will remain installed in /Users/me/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/ffi-1.9.25 for inspection.
Results logged to /Users/me/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/extensions/x86_64-darwin-16/2.4.0-static/ffi-1.9.25/gem_make.out
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 26
- Comments: 43
The following worked for me:
this worked for me on Mac
I spent many hours trying to install Jekyll on Mac OS 10.13.4 (High Sierra), I got this error :
The main cause of the build crash is the error below :
After a lot of google searches and a lot of tries nothing solves the issue (trying to install another version of ffi, etc…). Finally I realised that I had a version of Xcode that was not updated because High Sierra is too older to support the lastest version (Thank you Apple…). So I tried to enter the command
gcc -v
and I saw this line :That was the problem ! Even If I installed the latest Xcode Command Line Developer Tools, the old gcc provided with Xcode was still used. I entered the command
xcode-select -s /Library/Developer/CommandLineTools/
and the commandgcc -v
displayed the new version :With this version of gcc I could install Jekyll :
I hope this thread could help someone 😉
Try to switch ruby to homebrew version.
brew install ruby
brew link --overwrite ruby
If you need to have ruby first in your PATH run:
echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.bash_profile
For compilers to find ruby you may need to set:
export LDFLAGS="-L/usr/local/opt/ruby/lib"
export CPPFLAGS="-I/usr/local/opt/ruby/include"
For pkg-config to find ruby you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/ruby/lib/pkgconfig"
Thanks, @sujaysudheenda! This worked for me on MacOS Catalina:
gem install ffi -v '1.9.18' -- --with-cflags="-Wno-error=implicit-function-declaration"
I was having this same issue where I could not install native extensions which would fail when trying to include “ruby/config.h”.
I believe it was because I was using the ruby version installed with Homebrew. After upgrading to a new version of Ruby with Homebrew, I saw the following helpful message from Homebrew
Adding the following lines to my
~/.bash_profile
fixed the issue for me:Same problem on Apple M1 while installing cocoapods.
I have tried all of the above solutions but none of them worked for me , please can anyone tell me what’s the real issue…
Here is the mkmf.log file pkg-config --exists libffi" package configuration for libffi is not found have_header: checking for ffi.h… -------------------- no
"xcrun clang -o conftest -I/Users/eapple/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/universal-darwin18 -I/Users/eapple/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/ruby/backward -I/Users/eapple/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -g -Os -pipe -DHAVE_GCC_ATOMIC_BUILTINS conftest.c -L. -L/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib -L. -lruby.2.3.0 -lpthread -ldl -lobjc " checked program was: /* begin */ 1: #include “ruby.h” 2: 3: int main(int argc, char *argv) 4: { 5: return 0; 6: } / end */
“xcrun clang -I/Users/eapple/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/universal-darwin18 -I/Users/eapple/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/ruby/backward -I/Users/eapple/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -g -Os -pipe -DHAVE_GCC_ATOMIC_BUILTINS -c conftest.c” conftest.c:3:10: fatal error: ‘ffi.h’ file not found #include <ffi.h> ^~~~~~~ 1 error generated. checked program was: /* begin / 1: #include “ruby.h” 2: 3: #include <ffi.h> / end */
find_header: checking for ffi.h in /usr/local/include,/usr/include/ffi… -------------------- no
“xcrun clang -I/Users/eapple/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/universal-darwin18 -I/Users/eapple/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/ruby/backward -I/Users/eapple/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -g -Os -pipe -DHAVE_GCC_ATOMIC_BUILTINS -c conftest.c” conftest.c:3:10: fatal error: ‘ffi.h’ file not found #include <ffi.h> ^~~~~~~ 1 error generated. checked program was: /* begin / 1: #include “ruby.h” 2: 3: #include <ffi.h> / end */
“xcrun clang -I/Users/eapple/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/universal-darwin18 -I/Users/eapple/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/ruby/backward -I/Users/eapple/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -g -Os -pipe -DHAVE_GCC_ATOMIC_BUILTINS -I/usr/local/include -c conftest.c” conftest.c:3:10: fatal error: ‘ffi.h’ file not found #include <ffi.h> ^~~~~~~ 1 error generated. checked program was: /* begin / 1: #include “ruby.h” 2: 3: #include <ffi.h> / end */
“xcrun clang -I/Users/eapple/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/universal-darwin18 -I/Users/eapple/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/ruby/backward -I/Users/eapple/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -g -Os -pipe -DHAVE_GCC_ATOMIC_BUILTINS -I/usr/include/ffi -c conftest.c” conftest.c:3:10: fatal error: ‘ffi.h’ file not found #include <ffi.h> ^~~~~~~ 1 error generated. checked program was: /* begin / 1: #include “ruby.h” 2: 3: #include <ffi.h> / end */
have_header: checking for shlwapi.h… -------------------- no
“xcrun clang -I/Users/eapple/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/universal-darwin18 -I/Users/eapple/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/ruby/backward -I/Users/eapple/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -g -Os -pipe -DHAVE_GCC_ATOMIC_BUILTINS -c conftest.c” conftest.c:3:10: fatal error: ‘shlwapi.h’ file not found #include <shlwapi.h> ^~~~~~~~~~~ 1 error generated. checked program was: /* begin / 1: #include “ruby.h” 2: 3: #include <shlwapi.h> / end */
have_func: checking for rb_thread_call_without_gvl()… -------------------- yes
"xcrun clang -o conftest -I/Users/eapple/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/universal-darwin18 -I/Users/eapple/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/ruby/backward -I/Users/eapple/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -g -Os -pipe -DHAVE_GCC_ATOMIC_BUILTINS conftest.c -L. -L/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib -L. -lruby.2.3.0 -lpthread -ldl -lobjc " conftest.c:13:57: error: use of undeclared identifier ‘rb_thread_call_without_gvl’ int t(void) { void ((volatile p)()); p = (void (()()))rb_thread_call_without_gvl; return !p; } ^ 1 error generated. checked program was: /* begin */ 1: #include “ruby.h” 2: 3: /top/ 4: extern int t(void); 5: int main(int argc, char *argv) 6: { 7: if (argc > 1000000) { 8: printf(“%p”, &t); 9: } 10: 11: return 0; 12: } 13: int t(void) { void ((volatile p)()); p = (void (()()))rb_thread_call_without_gvl; return !p; } / end */
"xcrun clang -o conftest -I/Users/eapple/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/universal-darwin18 -I/Users/eapple/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/ruby/backward -I/Users/eapple/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -g -Os -pipe -DHAVE_GCC_ATOMIC_BUILTINS conftest.c -L. -L/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib -L. -lruby.2.3.0 -lpthread -ldl -lobjc " checked program was: /* begin */ 1: #include “ruby.h” 2: 3: /top/ 4: extern int t(void); 5: int main(int argc, char *argv) 6: { 7: if (argc > 1000000) { 8: printf(“%p”, &t); 9: } 10: 11: return 0; 12: } 13: extern void rb_thread_call_without_gvl(); 14: int t(void) { rb_thread_call_without_gvl(); return 0; } / end */
have_func: checking for ruby_native_thread_p()… -------------------- yes
"xcrun clang -o conftest -I/Users/eapple/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/universal-darwin18 -I/Users/eapple/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/ruby/backward -I/Users/eapple/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -g -Os -pipe -DHAVE_GCC_ATOMIC_BUILTINS conftest.c -L. -L/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib -L. -lruby.2.3.0 -lpthread -ldl -lobjc " checked program was: /* begin */ 1: #include “ruby.h” 2: 3: /top/ 4: extern int t(void); 5: int main(int argc, char *argv) 6: { 7: if (argc > 1000000) { 8: printf(“%p”, &t); 9: } 10: 11: return 0; 12: } 13: int t(void) { void ((volatile p)()); p = (void (()()))ruby_native_thread_p; return !p; } / end */
have_func: checking for ruby_thread_has_gvl_p()… -------------------- yes
"xcrun clang -o conftest -I/Users/eapple/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/universal-darwin18 -I/Users/eapple/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/ruby/backward -I/Users/eapple/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -g -Os -pipe -DHAVE_GCC_ATOMIC_BUILTINS conftest.c -L. -L/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib -L. -lruby.2.3.0 -lpthread -ldl -lobjc " conftest.c:13:57: error: use of undeclared identifier ‘ruby_thread_has_gvl_p’ int t(void) { void ((volatile p)()); p = (void (()()))ruby_thread_has_gvl_p; return !p; } ^ 1 error generated. checked program was: /* begin */ 1: #include “ruby.h” 2: 3: /top/ 4: extern int t(void); 5: int main(int argc, char *argv) 6: { 7: if (argc > 1000000) { 8: printf(“%p”, &t); 9: } 10: 11: return 0; 12: } 13: int t(void) { void ((volatile p)()); p = (void (()()))ruby_thread_has_gvl_p; return !p; } / end */
"xcrun clang -o conftest -I/Users/eapple/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/universal-darwin18 -I/Users/eapple/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/ruby/backward -I/Users/eapple/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -g -Os -pipe -DHAVE_GCC_ATOMIC_BUILTINS conftest.c -L. -L/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib -L. -lruby.2.3.0 -lpthread -ldl -lobjc " checked program was: /* begin */ 1: #include “ruby.h” 2: 3: /top/ 4: extern int t(void); 5: int main(int argc, char *argv) 6: { 7: if (argc > 1000000) { 8: printf(“%p”, &t); 9: } 10: 11: return 0; 12: } 13: extern void ruby_thread_has_gvl_p(); 14: int t(void) { ruby_thread_has_gvl_p(); return 0; } / end */
extconf.h is: /* begin / 1: #ifndef EXTCONF_H 2: #define EXTCONF_H 3: #define HAVE_RB_THREAD_CALL_WITHOUT_GVL 1 4: #define HAVE_RUBY_NATIVE_THREAD_P 1 5: #define HAVE_RUBY_THREAD_HAS_GVL_P 1 6: #define HAVE_FFI_PREP_CIF_VAR 1 7: #define USE_INTERNAL_LIBFFI 1 8: #endif / end */
@ffleming I am seeing all this success using your steps above however I am not one of them 😦
Admittedly I am new to working with Ruby etc and I am hoping that someone here might be able to help me. I am trying to install Jekyll on Catalina (ver 10.15.4) and have Ruby 2.7.0 installed.
When I run “gem install Jekyll” or “gem install --user-install bundler jekyll” (as per the Jekyll site, I get the following:
Am not sure if I am missing some parameters that I need to enter or dependencies missing. Any help for this newbie would be much appreciated.
Thanks in advance.
I’m on Mojave and @ffleming’s solution fixed the issue for me - thanks!
Thanks, @sujaysudheenda 🙌
This worked for me on MacOS Catalina: gem install ffi -v ‘1.9.23’ – --with-cflags=“-Wno-error=implicit-function-declaration”
In our case we install Ruby 2.7 using rvm and update the PATH
Remember compilers and pkg-config:
I hope this can help someone 😃
Has anyone been able to get this to work on an Apple Developer Kit (Silicon) Mac running Big Sur? I’ve tried all of the things above and none of them have worked for me.
Thanks @ffleming ! This worked for me on 10.13.6
@ffleming Likewise works for me on Catalina - thanks a lot, saved me having to downgrade after a couple of hours of searching.
cannot install not ffi nor jekyll on my mac
gem_make.out.txt
I am having a similar ffi gem compile error. Has anyone found a solution?
Same error here, though I’m on macOS 10.14.1 Mojave. Trying to
bundle install
a jekyll theme, and I get:So, I run:
gem install ffi -v '1.9.21' --source 'https://rubygems.org/'
which leads to: