【问题标题】:Installing Cocoapods via Ruby causes Error通过 Ruby 安装 Cocoapods 会导致错误
【发布时间】:2021-05-10 21:09:56
【问题描述】:

我尝试像这样安装 Cocoapods

sudo gem install cocoapods

这是我得到的输出:

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.14.2/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20210206-1353-ybitkb.rb extconf.rb
*** 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:546:in `block in try_link0'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/tmpdir.rb:93:in `mktmpdir'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:543:in `try_link0'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:570:in `try_link'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:672:in `try_ldflags'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1832:in `pkg_config'
    from extconf.rb:9: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.14.2/mkmf.log

extconf failed, exit code 1

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

基本上就是这样

/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in `try_do':编译器无法生成可执行文件。 (运行时错误) 您必须先安装开发工具。

我必须先安装哪些开发工具? xCode 以及 Xcode 命令行工具已安装。 我在 OS X 10.15.7 上,Xcode 是最新的。

【问题讨论】:

    标签: ruby xcode macos rubygems cocoapods


    【解决方案1】:

    几个小时后终于拿到了。 我按照this的指令,稍微改了一下

    1. 确保已安装 brew。如果不 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

    2. 将外壳设置为zsh curl -L http://install.ohmyz.sh | sh

    或者,设置路径

    1. eval "$(rbenv init -)"

    2. 安装 Ruby 版本管理器 brew update brew install rbenv ruby-build

    3. 安装 Ruby rbenv install 2.6 # 我使用我的系统默认版本号,因为我不确定它是否与我的 OS X 系统版本混淆。 rbenv global 2.6 rbenv rehash

    4. 将其添加到您的 zsh echo 'eval "$(rbenv init -)"' &gt;&gt; ~/.zshrc source ~/.zshrc

    这对我有用。所有其他的东西,比如安装 Xcode,接受 Xcode 许可证,Xcode 命令行工具都没有。

    【讨论】:

    • 我遇到了同样的问题,但这个解决方案对我有用
    【解决方案2】:

    或者干脆……?

    brew install cocoapods

    【讨论】:

      猜你喜欢
      • 2017-01-20
      • 2013-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多