rubyreact-nativecocoapodslibffi

Failed to build ffi gem native extension on mac


Tried to install cocoapods and other React Native pod installs. Installing the libffi gem native extension is part of the process, and it keeps failing with this output:

configure: error: C++ preprocessor "/lib/cpp" fails sanity check

The dependency is as follows:

An error occurred while installing ffi (1.15.4), and Bundler cannot
continue.

In Gemfile:
  cocoapods was resolved to 1.12.1, which depends on
    cocoapods-core was resolved to 1.12.1, which depends on
      typhoeus was resolved to 1.4.0, which depends on
        ethon was resolved to 0.14.0, which depends on
          ffi

I also tried to find a precompiled version of libffi instead of compiling from source but it is sadly not available in RubyGems.org


Solution

  • I fixed this by running:

    CXXCPP="$(xcrun --find clang)++ -E" arch -x86_64 gem install ffi

    My CPP path was not properly configured, so I had to explicitly pass it in. Hope this helps others running into the same problem.