SolvedCocoaPods Build issue with Xcode 12.3 - file not found #include "ruby/config.h"

Trying to install without using sudo with the following command.

gem install --user-install cocoapods

I saw a lot of errors and comments reported with Ruby on macOS with the same issue. Error generated is:

package configuration for libffi is not found "xcrun clang -o conftest -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin19 -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/backward -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.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.6/usr/lib -L. -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.Internal.sdk/usr/local/lib -arch x86_64 -lruby.2.6 " In file included from conftest.c:1: In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby.h:33: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/ruby.h:24:10: fatal error: 'ruby/config.h' file not found #include "ruby/config.h" ^~~~~~~~~~~~~~~ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/ruby.h:24:10: note: did not find header 'config.h' in framework 'ruby' (loaded from '/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks') 1 error generated. checked program was: /* begin */ 1: #include "ruby.h" 2: 3: int main(int argc, char **argv) 4: { 5: return 0; 6: } /* end */

I found that the build command used is:

xcrun clang -o conftest \ -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin19 \ -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/backward \ -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.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.6/usr/lib \ -L. -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.Internal.sdk/usr/local/lib \ -arch x86_64 \ -lruby.2.6

But, it needs to be

xcrun clang -o conftest \ -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin20 \ -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/backward \ -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.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.6/usr/lib \ -L. -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib \ -arch x86_64 \ -lruby.2.6

Notice the following changes:

Instead of universal-darwin19, it is universal-darwin20
Instead of MacOSX10.15.Internal.sdk, it is MacOSX.sdk

37 Answers

โœ”๏ธAccepted Answer

I just updated to Xcode 12.3 and I am hitting this issue. Seems like Xcode 12.3 broke the system ruby installation. This solved it for me:

cd $(xcode-select -p)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0 && ln -s universal-darwin20 universal-darwin19

Other Answers:

Seems to be an issue with macOS 10.15 and Xcode 12.
Combination of macOS 10.15 and Xcode 11 works fine.

I just update rurby version to 2.7.2, resolve the problem

I didn't want to use brew or ports, so I had to downgrade Xcode to make it work.

Can confirm Command Line Tools 11.5 works on Catalina (10.15).

For those unfamiliar with changing/downgrading Command Line Tools:

  • Download Command Line Tools 11.5 from Apple Developer Downloads
  • sudo rm -rf /Library/Developer/CommandLineTools
  • Install Command Line Tools from .dmg/.pkg
  • sudo xcode-select --switch /Library/Developer/CommandLineTools
  • [sudo] gem install [--user-install] cocoapods
  • sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer

I just updated to Xcode 12.3 and I am hitting this issue. Seems like Xcode 12.3 broke the system ruby installation. This solved it for me:

cd $(xcode-select -p)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0 && ln -s universal-darwin20 universal-darwin19

I just did a clean install of Catalina and the path above did not exist. The path I found it under is;

/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0

The second part -

ln -s universal-darwin20 universal-darwin19

worked for me once I found the right directory.

Anyone else with this issue, this is what worked for me:

  1. curl -sSL https://get.rvm.io | bash -s stable
  2. close and reopen terminal
  3. rvm install ruby@latest
  4. rvm use ruby-3.0.0 --default

Update if you're using Xcode 13.1

cd $(xcode-select -p)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0 && ln -s universal-darwin21 universal-darwin20

More Issues: