macOS10.15、xcode12 安装cocoapods失败

2021-04-01  本文已影响0人  啸狼天

最近安装cocoapods 失败,报这个错误,在网上早了很多的方法都无法解决

我使用

sudo gem install -n /usr/local/bin cocoapods

安装后,得到这个错误

 sudo gem install -n /usr/local/bin cocoapods

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

    current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.0/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /Library/Ruby/Site/2.6.0 -r ./siteconf20210401-20410-h6c3qx.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
    --without-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=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/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
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in `block in try_compile'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:534:in `with_werror'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in `try_compile'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1109:in `block in have_header'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:959:in `block in checking_for'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block (2 levels) in postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block in postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:357:in `postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:958:in `checking_for'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1108: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:

  /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.15.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.0 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.15.0/gem_make.out

安装他人的方法 仍然没有解决

捣鼓了一天时间,ruby rvm brew 都重装升级了个遍 还是不行;仔细查看报错原因,是因为 ffi_prep_closure_loc 这个隐式声明的方法在CommandLineTools/SDKs/MacOSX10.14.sdk中没有找到导致的。于是,查看了/Library/Developer/CommandLineTools/SDKs/目录下得文件:

bogon:SDKs xxx$ ls -a

. .. MacOSX.sdk MacOSX10.14.sdk MacOSX10.15.sdk MacOSX11.1.sdk
目录下一共有三个版本的sdk文件:MacOSX10.14.sdk MacOSX10.15.sdk MacOSX11.1.sdk

不清楚为什么ruby会引用MacOSX10.14.sdk中的文件,本人电脑系统是10.15的,于是,删除了MacOSX10.14.sdk这个文件,重新安装cocoapods

sudo gem install -n /usr/local/bin cocoapods

最后找到一篇文章 https://stackoverflow.com/questions/20939568/error-error-installing-cocoapods-error-failed-to-build-gem-native-extension#
才解决

解决过程如下

 brew install cocoapods 
 
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/cocoapods-1.10.1.catalina.b
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/3a05cecba1a15c8cad8ba
######################################################################## 100.0%
==> Pouring cocoapods-1.10.1.catalina.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.10.1: 13,132 files, 30.4MB

报如上错误,按照提示一一解决就行

MacBook-Pro:~ mars$ pod --version
1.8.4
MacBook-Pro:~ mars$ which pod
/usr/local/bin/pod

MacBook-Pro:~ mars$ rm '/usr/local/bin/pod'
override rwxr-xr-x  root/admin for /usr/local/bin/pod? yes
MacBook-Pro:~ mars$ which pod
MacBook-Pro:~ mars$ brew link --overwrite cocoapods
Linking /usr/local/Cellar/cocoapods/1.10.1... 2 symlinks created.
MacBook-Pro:~ mars$ pod --version
1.10.1
MacBook-Pro:~ mars$ pod setup
Setup completed
上一篇 下一篇

猜你喜欢

热点阅读