无法安装可可豆荚

时间:2020-07-02 15:52:35

标签: rubygems cocoapods homebrew

我想在MacOS上安装cocoapods以运行pod命令。但是在做

sudo gem install cocoa-pods

我得到以下信息:

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

mkmf.log文件为:

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 */


并运行

brew install libffi

给予:

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

该如何解决?

当我使用brew安装cocoapods时,我得到:

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

当我这样做时:

pod --version

我得到:

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)

当我运行pod命令时,它想找到gem,而不是使用brew安装的pod。

-编辑-

酿造配置

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

3 个答案:

答案 0 :(得分:12)

我有一个类似的问题。我通过安装最新版本的ruby(2.7.2)解决了问题。

首先安装Ruby Version Manager rvm:

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

然后安装最新版本的ruby:

rvm install ruby-2.7.2

最后再次尝试安装cocoapods:

sudo gem install cocoapods

答案 1 :(得分:1)

这是我在Mojave机器上所做的事情:

  • brew reinstall cocoapods
  • brew link --overwrite cocoapods,覆盖默认的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检查安装和版本测试

$ 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

让我知道它是否有效,如果仍然有问题,请附上您的brew config

答案 2 :(得分:0)

我认为最可靠的解决方案是使用:

brew install cocoapods

哪个应该自己解决丢失/损坏的依赖项。

PS:这显然涉及安装 brew,但我敢打赌,您的系统中已经有了它。