ios 错误:安装 cocoapods 时出错:错误:无法构建 gem 本机扩展

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20939568/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 23:00:09  来源:igfitidea点击:

ERROR: Error installing cocoapods: ERROR: Failed to build gem native extension

iososx-maverickscocoapods

提问by gran33

I am trying to install cocoapods to my MacBook Pro running with OSX 10.9.1 (new Mavericks) and after type gem install cocoapodsI get the following error:

我正在尝试将 cocoapods 安装到运行 OSX 10.9.1(新 Mavericks)的 MacBook Pro 上,键入后gem install cocoapods出现以下错误:

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

        "/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby" -rubygems /usr/local/rvm/gems/ruby-1.9.3-p194/gems/rake-10.1.1/bin/rake RUBYARCHDIR=/Users/rangreenberg/gems/gems/xcodeproj-0.14.1/ext RUBYLIBDIR=/Users/rangreenberg/gems/gems/xcodeproj-0.14.1/ext
/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for -std=c99 option to compiler... *** 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/rvm/rubies/ruby-1.9.3-p194/bin/ruby
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:491:in `block in try_compile'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:443:in `with_werror'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:491:in `try_compile'
    from extconf.rb:24:in `block in <main>'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:790:in `block in checking_for'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:284:in `block (2 levels) in postpone'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:284:in `block in postpone'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:280:in `postpone'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:789:in `checking_for'
    from extconf.rb:23:in `<main>'
rake aborted!
Command failed with status (1): [/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/...]

Tasks: TOP => default => ext
(See full trace by running task with --trace)


Gem files will remain installed in /Users/rangreenberg/gems/gems/xcodeproj-0.14.1 for inspection.
Results logged to /Users/rangreenberg/gems/gems/xcodeproj-0.14.1/ext/xcodeproj/gem_make.out

回答by Kevin

You need to install Xcode's developer tools. The easiest way to do this is through terminal (this question)

您需要安装 Xcode 的开发人员工具。最简单的方法是通过终端(这个问题

xcode-select --install

回答by anka

I fixed the problem by using ruby 2.0 (which is the preferred way on mavericks) or greater. In case you are using rvm just change to the correct ruby with:

我通过使用 ruby​​ 2.0(这是小牛的首选方式)或更高版本解决了这个问题。如果您使用的是 rvm,只需更改为正确的 ruby​​:

rvm use ruby-2.0

After that gem install cocoapodsworked correctly. To be more specific, I was using:

之后gem install cocoapods工作正常。更具体地说,我使用的是:

OSX 10.9.2
ruby-2.0.0-p353
cocoapods-0.32.1

回答by Mr Heelis

if you're also seeing error: active developer path.. does not existyou may also have to do this

如果你也看到error: active developer path..does not exist你可能也必须这样做

$ sudo xcode-select --reset

回答by averem

First as wrote "Kevin" try to run in terminal:

首先写“凯文”尝试在终端中运行:

xcode-select --install

If it doesn't help you download tools manually from apple developer site:

如果它不能帮助您从苹果开发者网站手动下载工具:

It helped me.

它帮助了我。

回答by xdevx

Alright,

好吧,

I had the same issue. Tried to install pods to my project but never worked out. I updated Xcode, Updated Command Line tools, reinstalled cocoapods... almost everything.

我遇到过同样的问题。试图将 pod 安装到我的项目中,但从未成功。我更新了 Xcode,更新了命令行工具,重新安装了 cocoapods ......几乎所有东西。

Sitting on my ass , writing pod in terminal showed up a screen listing available commands.

坐在我的屁股上,在终端中编写 pod 会显示一个列出可用命令的屏幕。

I read all of them and noticed the command

我阅读了所有这些并注意到了命令

pod setup

which does

哪个

+ setup               Setup the CocoaPods environment

After this line of code, my problem was fixed.

在这行代码之后,我的问题就解决了。

I hope my solution help other people in trouble like me.

我希望我的解决方案可以帮助像我一样遇到麻烦的其他人。

回答by showtimefan

I fix the problem by follow step:

我按照以下步骤解决问题:

1:rvm install 2.0.0

1:rvm安装2.0.0

2:rvm list * ruby-1.9.3-p545 [ x86_64 ] => ruby-2.0.0-p451 [ x86_64 ]

2:rvm 列表 * ruby​​-1.9.3-p545 [ x86_64 ] => ruby​​-2.0.0-p451 [ x86_64 ]

3:rvm 2.0.0 —default

3:rvm 2.0.0 —默认

4:pod update

4:豆荚更新

回答by voghDev

I was getting this error and had to completely reinstall cocoapods to fix it. Finally worked. Maybe this solution suits for anyone else.

我遇到了这个错误,不得不完全重新安装 cocoapods 来修复它。终于工作了。也许这个解决方案适合其他人。

sudo rm -rf home_folder/.cocoapods/

After that, did again

之后,又做了

pod setup

and installed my libraries from zero, and everything worked.

并从零开始安装我的库,一切正常。

Hope it helps!

希望能帮助到你!

回答by ayberkt

I was having the same exact problem, although I had the latest version of the xcode command-line tools.

尽管我有最新版本的 xcode 命令行工具,但我遇到了同样的问题。

If you have homebrew installed, do brew install apple-gcc42. This immediately solved it for me.

如果您安装了自制软件,请执行brew install apple-gcc42. 这立即为我解决了。

回答by Tony Togara

I was facing quite a similar error, and it was my first time installing CocoaPods on macOS Catalina. Finally managed by installing Xcode Commandline Tools. Type in the following command into your Terminal. (As of this day, this file is around 248.3mb)

我遇到了类似的错误,这是我第一次在 macOS Catalina 上安装 CocoaPods。最后通过安装 Xcode 命令行工具进行管理。在终端中输入以下命令。(截至今天,该文件约为 248.3mb)

xcode-select --install

A dialog should appear asking you to approve the download and installation. It might take a while to download depending on your internet speed. Once the installation is successful. Attempt to install CocoaPods once more with the following command in Terminal.

应出现一个对话框,要求您批准下载和安装。下载可能需要一段时间,具体取决于您的互联网速度。一旦安装成功。尝试在终端中使用以下命令再次安装 CocoaPods。

sudo gem install cocoapods

Once complete use the following command to confirm if installation was successful

完成后使用以下命令确认安装是否成功

pod setup --verbose

回答by Jigar Thakkar

Run following command

运行以下命令

 brew cleanup -d -v 

Then run below command

然后运行下面的命令

brew install cocoapods 

Note: If you see failed to link then run brew link cocoapods

注意:如果您看到无法链接,请运行 brew link cocoapods

This is how it get solved for me

这就是它为我解决的方法