Unable to install cocoa pods

。_饼干妹妹 提交于 2020-12-08 15:52:31

问题


I want to install cocoapods on MacOS to run the pod command. But on doing

sudo gem install cocoa-pods

I get the following:

Building native extensions. This could take a while...
ERROR:  Error installing cocoapods:
    ERROR: Failed to build gem native extension.

    current directory: /usr/local/lib/ruby/gems/2.7.0/gems/ffi-1.13.1/ext/ffi_c
/usr/local/opt/ruby/bin/ruby -I /usr/local/Cellar/ruby/2.7.1_2/lib/ruby/2.7.0 -r ./siteconf20200702-22528-1o4wbn0.rb extconf.rb
checking for ffi.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/usr/local/Cellar/ruby/2.7.1_2/bin/$(RUBY_BASE_NAME)
    --with-ffi_c-dir
    --without-ffi_c-dir
    --with-ffi_c-include
    --without-ffi_c-include=${ffi_c-dir}/include
    --with-ffi_c-lib
    --without-ffi_c-lib=${ffi_c-dir}/lib
    --enable-system-libffi
    --disable-system-libffi
    --with-libffi-config
    --without-libffi-config
    --with-pkg-config
    --without-pkg-config
    --with-ffi-dir
    --without-ffi-dir
    --with-ffi-include
    --without-ffi-include=${ffi-dir}/include
    --with-ffi-lib
    --without-ffi-lib=${ffi-dir}/lib
/usr/local/Cellar/ruby/2.7.1_2/lib/ruby/2.7.0/mkmf.rb:471:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /usr/local/Cellar/ruby/2.7.1_2/lib/ruby/2.7.0/mkmf.rb:613:in `try_cpp'
    from /usr/local/Cellar/ruby/2.7.1_2/lib/ruby/2.7.0/mkmf.rb:1124:in `block in have_header'
    from /usr/local/Cellar/ruby/2.7.1_2/lib/ruby/2.7.0/mkmf.rb:971:in `block in checking_for'
    from /usr/local/Cellar/ruby/2.7.1_2/lib/ruby/2.7.0/mkmf.rb:361:in `block (2 levels) in postpone'
    from /usr/local/Cellar/ruby/2.7.1_2/lib/ruby/2.7.0/mkmf.rb:331:in `open'
    from /usr/local/Cellar/ruby/2.7.1_2/lib/ruby/2.7.0/mkmf.rb:361:in `block in postpone'
    from /usr/local/Cellar/ruby/2.7.1_2/lib/ruby/2.7.0/mkmf.rb:331:in `open'
    from /usr/local/Cellar/ruby/2.7.1_2/lib/ruby/2.7.0/mkmf.rb:357:in `postpone'
    from /usr/local/Cellar/ruby/2.7.1_2/lib/ruby/2.7.0/mkmf.rb:970:in `checking_for'
    from /usr/local/Cellar/ruby/2.7.1_2/lib/ruby/2.7.0/mkmf.rb:1123:in `have_header'
    from extconf.rb:10:in `system_libffi_usable?'
    from extconf.rb:42:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /usr/local/lib/ruby/gems/2.7.0/extensions/x86_64-darwin-19/2.7.0/ffi-1.13.1/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /usr/local/lib/ruby/gems/2.7.0/gems/ffi-1.13.1 for inspection.
Results logged to /usr/local/lib/ruby/gems/2.7.0/extensions/x86_64-darwin-19/2.7.0/ffi-1.13.1/gem_make.out

The mkmf.log file is:

package configuration for libffi is not found
"clang -o conftest -I/usr/local/Cellar/ruby/2.7.1_2/include/ruby-2.7.0/x86_64-darwin19 -I/usr/local/Cellar/ruby/2.7.1_2/include/ruby-2.7.0/ruby/backward -I/usr/local/Cellar/ruby/2.7.1_2/include/ruby-2.7.0 -I.  -I/usr/local/opt/libyaml/include -I/usr/local/opt/openssl@1.1/include -I/usr/local/opt/readline/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens  -fno-common -pipe conftest.c  -L. -L/usr/local/Cellar/ruby/2.7.1_2/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl@1.1/lib -L/usr/local/opt/readline/lib -L. -fstack-protector-strong -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl@1.1/lib -L/usr/local/opt/readline/lib     -lruby.2.7   "
In file included from conftest.c:1:
In file included from /usr/local/Cellar/ruby/2.7.1_2/include/ruby-2.7.0/ruby.h:33:
In file included from /usr/local/Cellar/ruby/2.7.1_2/include/ruby-2.7.0/ruby/ruby.h:29:
/usr/local/Cellar/ruby/2.7.1_2/include/ruby-2.7.0/ruby/defines.h:126:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
         ^~~~~~~~~
1 error generated.
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return !!argv[argc];
6: }
/* end */


and running

brew install libffi

gives:

% brew install libffi
Warning: libffi 3.3 is already installed and up-to-date
To reinstall 3.3, run `brew reinstall libffi`

How to fix this?

And when I install cocoapods using brew, I get:

Warning: cocoapods 1.9.3 is already installed and up-to-date
To reinstall 1.9.3, run `brew reinstall cocoa-pods

Yet when I do:

pod --version

I get:

pod --version
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/universal-darwin19/rbconfig.rb:229: warning: Insecure world writable dir /Users/prikshetsharma/Library in PATH, mode 040777
Traceback (most recent call last):
    2: from /usr/local/bin/pod:23:in `<main>'
    1: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:302:in `activate_bin_path'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:283:in `find_spec_for_exe': can't find gem cocoapods (>= 0.a) with executable pod (Gem::GemNotFoundException)

When I run the pod command, it wants to find the gem, and not the pod installed using brew.

-- EDIT --

The brew config

HOMEBREW_VERSION: 2.4.3
ORIGIN: https://github.com/Homebrew/brew
HEAD: c69d97aaa5ba07e8c2af3708c8093ca0875cfb06
Last commit: 3 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 2820accc9a0486a8d5f0766bcf01fb560b9d3f9f
Core tap last commit: 14 hours ago
HOMEBREW_PREFIX: /usr/local
HOMEBREW_MAKE_JOBS: 16
CPU: 16-core 64-bit kabylake
Homebrew Ruby: 2.6.3 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
Clang: 11.0 build 1103
Git: 2.24.3 => /Applications/Xcode.app/Contents/Developer/usr/bin/git
Curl: 7.64.1 => /usr/bin/curl
Java: 1.8.0_241
macOS: 10.15.5-x86_64
CLT: 11.5.0.0.1.1588476445
Xcode: 11.5


回答1:


I had a similar issue. I solved by installing the latest version of ruby (2.7.2).

First install the Ruby Version Manager rvm:

curl -L https://get.rvm.io | bash -s stable

Then install the latest version of ruby:

rvm install ruby-2.7.2

Finally try again to install the cocoapods:

sudo gem install cocoapods



回答2:


Here is what I did on my Mojave machine:

  • brew reinstall cocoapods
  • brew link --overwrite cocoapods, override the default pod
$ brew reinstall cocoapods
==> Downloading https://homebrew.bintray.com/bottles/cocoapods-1.9.3.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/07/074e5b53b7a054c132582183dcf47546ddd028a7beb9fcdc653fe4a43225bcf3?__gda__=exp=1593894546~hmac=8b
######################################################################## 100.0%
==> Reinstalling cocoapods
==> Pouring cocoapods-1.9.3.mojave.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/pod
Target /usr/local/bin/pod
already exists. You may want to remove it:
  rm '/usr/local/bin/pod'

To force the link and overwrite all conflicting files:
  brew link --overwrite cocoapods

To list all files that would be deleted:
  brew link --overwrite --dry-run cocoapods

Possible conflicting files are:
/usr/local/bin/pod
/usr/local/bin/xcodeproj
==> Summary
🍺  /usr/local/Cellar/cocoapods/1.9.3: 12,705 files, 28.0MB

$ brew link --overwrite cocoapods
Linking /usr/local/Cellar/cocoapods/1.9.3... 2 symlinks created

ls check the installation and version test

$ ls -al $(which pod)
lrwxr-xr-x  1 rchen  staff  33 Jul  4 16:17 /usr/local/bin/pod -> ../Cellar/cocoapods/1.9.3/bin/pod

$ pod --version
1.9.3

Let me know if it works, also attach your brew config if it is still an issue.



来源:https://stackoverflow.com/questions/62700347/unable-to-install-cocoa-pods

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!