当我试图安装最新版本的compass (https://rubygems.org/gems/compass/versions/1.0.0.alpha.17)时,我得到以下错误。

ERROR:  Error installing compass:
ERROR: Failed to build gem native extension.

 ERROR:  Error installing compass:
  ERROR: Failed to build gem native extension.

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb
checking for ffi.h... no
checking for ffi.h in /usr/local/include,/usr/include/ffi... yes
checking for ffi_call() in -lffi... yes
checking for ffi_prep_closure()... yes
checking for ffi_raw_call()... no
checking for rb_thread_blocking_region()... yes
checking for rb_thread_call_with_gvl()... yes
checking for rb_thread_call_without_gvl()... yes
checking for ffi_prep_cif_var()... no
creating extconf.h
creating Makefile

make "DESTDIR=" clean

make "DESTDIR="
compiling AbstractMemory.c
compiling ArrayType.c
compiling Buffer.c
compiling Call.c
Call.c:303:5: warning: implicit declaration of function 'rb_thread_call_without_gvl' is invalid in C99 [-Wimplicit-function-declaration]
    rbffi_thread_blocking_region(call_blocking_function, data, (void *) -1, NULL);
    ^
./Thread.h:78:39: note: expanded from macro 'rbffi_thread_blocking_region'
# define rbffi_thread_blocking_region rb_thread_call_without_gvl
                                      ^
1 warning generated.
compiling ClosurePool.c
compiling DataConverter.c
DataConverter.c:43:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^
1 warning generated.
compiling DynamicLibrary.c
compiling ffi.c
compiling Function.c
Function.c:479:33: warning: incompatible pointer types passing 'VALUE (void *)' to parameter of type 'void *(*)(void *)' [-Wincompatible-pointer-types]
        rb_thread_call_with_gvl(callback_with_gvl, &cb);
                                ^~~~~~~~~~~~~~~~~
Function.c:102:46: note: passing argument to parameter 'func' here
extern void *rb_thread_call_with_gvl(void *(*func)(void *), void *data1);
                                             ^
Function.c:563:9: warning: implicit declaration of function 'rb_thread_call_without_gvl' is invalid in C99 [-Wimplicit-function-declaration]
        rb_thread_call_without_gvl(async_cb_wait, &w, async_cb_stop, &w);
        ^
Function.c:738:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
3 warnings generated.
compiling FunctionInfo.c
compiling LastError.c
compiling LongDouble.c
compiling MappedType.c
compiling MemoryPointer.c
compiling MethodHandle.c
compiling Platform.c
compiling Pointer.c
compiling Struct.c
compiling StructByReference.c
compiling StructByValue.c
compiling StructLayout.c
compiling Thread.c
compiling Type.c
compiling Types.c
compiling Variadic.c
linking shared-object ffi_c.bundle
clang: error: unknown argument: '-multiply_definedsuppress' [-Wunused-command-line-argument-hard-error-in-future]
clang: note: this will be a hard error (cannot be downgraded to a warning) in the future
make: *** [ffi_c.bundle] Error 1

make failed, exit code 2

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

这是怎么回事?如何正确安装最新的指南针?


当前回答

为了在Mac OS X 10.10 (Yosemite)上安装指南针,必须执行以下操作:

1. 设置Ruby环境

确保安装了ruby并且是最新的:ruby -v 更新gem的sudo gem Update——system

2. 搭建MAC环境

安装Xcode命令行工具,这是安装Compass的关键。

xcode-select --install

安装Xcode命令行工具是Compass在OS X上工作的关键

3.安装指南针

sudo gem install compass

其他回答

最好的方法是sudo apt-get install ruby-compass来安装指南针。

首先必须从Ruby 2.6升级到3.0(参见https://rvm.io/):)

$ curl -sSL https://get.rvm.io | bash -s stable --ruby
$ source /Usrs/myuser/.rvm/scripts/rvm

然后我必须在本地安装它,否则Mac OSX权限不会让我升级它(见错误:当执行gem…(Errno::EPERM)操作不允许)

$ sudo gem install -n /usr/local/bin compass

我不完全确定首先安装rvm是否有必要,但它对升级ruby是有用的。

在Mac上安装Ruby宝石是一个常见的困惑和沮丧的来源。不幸的是,大多数解决方案都是不完整的,过时的,并且提供了糟糕的建议。这里投票最多的答案是使用sudo,你永远都不需要这样做,特别是如果你不理解它是做什么的。

了解为什么你不应该使用sudo来安装宝石。

错误“未能构建gem本机扩展”是由于苹果命令行工具未安装。但是,安装它们并不一定会为您提供一个合适的Ruby环境。

在更高的层面上,Ruby设置有5个步骤,我在Mac上安装Ruby gems的最终指南中详细介绍了这些步骤。它解释了为什么会出现这个错误,比较了各种解决方案,为什么有些解决方案比其他解决方案更好,以及为什么不应该使用sudo。

我在这个回答中也写了这些步骤: https://stackoverflow.com/a/54873916/928191

你必须有gcc,json_pure

我从几个帖子上收集了一些信息

Sudo gem卸载sass 须藤宝石卸载罗盘 Sudo gem update—system Gem安装json_pure(如果你已经继续下一步) Sudo yum安装GCC GCC -c++(如果你已经有继续下一步) Sudo gem安装sass 须藤宝石安装指南针

嗨,如果** sudo宝石更新-系统**不工作,你在更新中得到一个错误,然后使用

Sudo gem更新—系统2.7.8

Gem安装过度

也就是运行时这个错误已经被放置在终端中。

Failed to build gem native extension

请也这样做

xcode-select --install

它也会解决这个问题