安装导轨时的"Failed to build gem native extension"



我是终端的新手,所以请耐心等待。成功完成以下安装(按此特定顺序):

  • xCode 4.5
  • RVM 1.16
  • 海湾合作委员会 4.2.1
  • 红宝石 1.9.3

尝试安装 Rails("gem install rails")时,安装开始,但随后中断并显示错误:"无法构建 gem 本机扩展"。不知道这指的是什么。想法?我需要事先安装的其他东西?
在我第一次尝试安装Rails时,我不小心用sudo运行了它。这会影响什么吗?

编辑:和输出 -

Building native extensions.  This could take a while...
ERROR:  Error installing rails:
    ERROR: Failed to build gem native extension.
        /Users/staffanestberg/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
creating Makefile
make
compiling generator.c
make: /usr/bin/gcc-4.2: No such file or directory
make: *** [generator.o] Error 1
Gem files will remain installed in /Users/staffanestberg/.rvm/gems/ruby-1.9.3-p194/gems/json-1.7.5 for inspection.
Results logged to /Users/staffanestberg/.rvm/gems/ruby-1.9.3-p194/gems/json-1.7.5/ext/json/ext/generator/gem_make.out


编辑:使用iouri的建议解决。在.bash-profile中添加export CC=gcc,然后为正确的编译器创建一个符号链接,

sudo ln -sf /usr/bin/llvm-gcc-4.2 /usr/bin/gcc-4.2

确保您首先安装了适用于 Xcode 的命令行工具、Xcode>首选项>下载>组件。然后将此行添加到主文件夹中的.bash_profile文件中~/.bash_profile

export CC=gcc

仔细检查您的/usr/bin 中是否有 gcc(可能是符号链接)(很可能),并且它指向有效的 gcc 编译器,例如:gcc -> llvm-gcc-4.2

您可能需要重新启动终端才能使此更改生效。

Ruby 还没有完全准备好进行 LLVM 编译,这包括 clang,至少有一个已知的 isue 与 Fibers,但根据 LLVM 版本,可能会出现其他问题。

修复它的正确方法是获得gcc-4.2有很多方法,最好的方法在需求中描述:

rvm get stable
rvm reload
rvm requirements run
rvm reinstall 1.9.3

最新更新