构建本地扩展宝石失败(安装Compass)

302
当我尝试安装最新版本的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

"

这里发生了什么?如何安装最新版的Compass而不出现错误?

"

请确保您的系统上安装了make。 - Sorter
26个回答

604

试一试这个,然后再尝试安装compass

apt-get install ruby-dev

40
这将修复Ubuntu上的错误,但似乎OP正在使用OSX。 - mhnagaoka
30
使用“yum install ruby-devel”在CentOS上运行,这相当于安装Ruby开发工具包。谢谢! - B2F
8
很有趣,在一个关于 OSx 问题的回答中找到解决我的 Ubuntu 问题的方法。尽管如此,你的答案确实解决了我的问题,所以我给了你赞。谢谢! - e-sushi
2
我认为安装ruby-dev有所帮助,但我还必须安装gcc和make。错误信息并没有非常明确说明这一点。 - Balmipour
3
有什么办法可以让这个在Windows上运行?我使用 choco install ruby2.devkit 安装了Ruby开发工具,但它仍然无法正常工作。 - jtate
显示剩余6条评论

141

为了在 Mac OS X 10.10(Yosemite)上安装 Compass,必须执行以下步骤:

1. 设置 Ruby 环境

  • 确保 ruby 已安装并更新至最新版本:ruby -v
  • 更新 gem 的版本:sudo gem update --system

2. 设置 MAC 环境

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

xcode-select --install
安装Xcode命令行工具是在Mac OS X上使用Compass的关键。
安装Compass。
sudo gem install compass

3
对我来说,这正是正确的答案,需要使用Xcode命令行工具。 - svnm
2
谢谢,对我有用,你是正确的,Xcode命令行工具是关键。 - marsaldev
5
这对我有用,但还需要增加一步操作——您需要启动XCODE,以便您可以接受许可协议并让其完成设置。也许值得将此附加到您的答案中。 - Bruford
通过 GUI 接受更新(协议条款)也起作用了。 - Cassio Cabral
在最近更新的MacBook Pro上升级到Sierra 10.12.6后,在运行sudo gem install compass之前,我还需要运行“sudo xcodebuild -license”以接受条款和条件。 - Joserra

48
最好的方法是使用sudo apt-get install ruby-compass安装compass。

1
哇,有时候真的很简单^^ 尝试使用gem安装compass,但是gem无法解决一些依赖关系。使用apt-get就可以了!谢谢 - stollr

39

您可以在Debian中尝试使用以下命令:

sudo apt-get install gcc ruby-dev rubygems compass

适用于 Fedora、Centos

yum -y install gcc ruby-devel rubygems compass

对我有效。


5
我还需要安装make - cweiske
3
ruby-dev 发挥了关键作用。https://dev59.com/AmIj5IYBdhLWcg3wKiPs - Bernhard Döbler

30

我也曾经遇到了同样的问题,为此苦恼了大约3个小时。从Compass 1.0.alpha19开始,要求使用rvm版本1.9.3。

虽然有几篇帖子没有被收集起来(或翻译成了“无法解决的帖子”),但对我起作用的方法如下:

  1. sudo gem uninstall sass
  2. sudo gem uninstall compass
  3. rvm install ruby-1.9.3-p448
  4. sudo gem install sass --pre
  5. sudo gem install compass --pre

这样就可以解决问题了。希望它对你也有效!


我最近遇到了同样的问题,但是是在新版本上。我的解决方法是使用aptitude卸载之前安装的ruby版本,然后按照http://rvm.io/rvm/install的说明重新安装。使用新的ruby/rvm版本后,compass成功构建。 - adosaiguas
2
谢谢,非常有帮助。我将第三步更改为 rvm install ruby-2.1.2,因为 1.9.3 不再更新。 - timelfelt

25
为了解决这个问题,我必须确保我有最新版本的Ruby和宝石gem update --system; 然后,我必须确保安装了Xcode和命令行工具:xcode-select --install

2
xcode-select --install 已经执行,但对我来说并没有解决问题。 - Ade

15

在 Mac OS 上,您需要安装此功能!

xcode-select --install

macOS 11.2 BigSur 尝试安装 sudo gem install compass 时出现了 OP 错误。安装 xcode 解决了问题,我终于可以安装 compass 了。非常感谢! - leymannx

14

如果您使用的是Ubuntu操作系统,建议尝试安装build-essential软件包。

apt install build-essential

我在全新安装的Ubuntu上安装gem时遇到了一些问题,这个解决方案对我有用。


我也遇到了同样的问题。希望更多的人能够点赞支持。 - Sorter
这对我来说是答案。 - Ngọc Nguyễn

11

嗨,在Mac上让它工作真是一项挑战,所以这里提供一个解决方案:

  1. 安装macports
  2. 安装rvm
  3. 重新启动终端
  4. 运行rvm requirements,然后运行rvm install 2.1
  5. 最后一步是运行gem install compass --pre

我不确定,但Mavericks上的ruby版本不支持本地扩展等...所以如果你像我一样指向其他ruby版本(例如2.1),它就可以正常工作。


我建议不要使用MacPorts。 - nomis

6

不确定为什么这些都没有被标记为正确的答案,但我通过谷歌搜索来到了这里,所以我会传递一下我知道的...

@paul_g的方法对我来说非常接近,在我的Mac osx10.9 Retina上的步骤如下:

  • 安装macports
  • 安装rvm(稳定版附带--insecure标志以解决SSL相关问题)$ \curl -sSL --insecure https://get.rvm.io | bash -s stable --ruby
  • 重新启动Terminal / Resource your profile
  • 运行rvm requirements --with-gcc=clang您无需更新Ruby,因为您已下载了最新的稳定版本
  • 最后一步运行gem install compass --pre

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接