我试图将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

当前回答

好了,

我也有同样的问题。试图安装豆荚到我的项目,但从未成功。我更新了Xcode,更新了命令行工具,重新安装cocoapods……几乎一切。

坐在我的屁股上,在终端上写pod时,屏幕上显示了可用的命令。

我读了所有的文件,注意到了其中的命令

pod setup

+ setup               Setup the CocoaPods environment

写完这行代码后,我的问题就解决了。

我希望我的解决方案能帮助其他和我一样有麻烦的人。

其他回答

这应该不浅桶和核心回购。

brew tap homebrew/cask

其次是…

brew tap homebrew/core

我也遇到了同样的问题,尽管我使用的是最新版本的xcode命令行工具。

如果你安装了自制程序,请安装apple-gcc42。这立刻解决了我的问题。

我也有同样的问题,我只是修改了我的/usr/local/include文件夹到/usr/local/include_old

我得到这个错误,必须完全重新安装cocoapods来修复它。最后工作。也许这个解决方案适用于其他任何人。

sudo rm -rf home_folder/.cocoapods/

之后,又做了一次

pod setup

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

希望能有所帮助!

brew reinstall ruby

将以下内容添加到您的路径中

export PATH="/usr/local/opt/ruby/bin:$PATH"

如果需要,添加这些标志。

export LDFLAGS="-L/usr/local/opt/ruby/lib"
export CPPFLAGS="-I/usr/local/opt/ruby/include"