简体   繁体   English

无法构建 gem 本机扩展(安装 Compass)

[英]Failed to build gem native extension (installing Compass)

When I attempt to install the latest version of compass ( https://rubygems.org/gems/compass/versions/1.0.0.alpha.17 ), I get the following error.当我尝试安装最新版本的指南针 ( 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

What's going on here?这里发生了什么? How do I install the latest compass without error?如何正确安装最新的指南针?

试试这个,然后再次尝试安装指南针

apt-get install ruby-dev

In order to install compass On Mac OS X 10.10 (Yosemite)had to perform the following:为了在 Mac OS X 10.10 (Yosemite) 上安装指南针,必须执行以下操作:

1. Set Up Ruby Environment 1. 搭建 Ruby 环境

  • Ensure ruby is installed and up to date: ruby -v确保安装了 ruby​​ 并且是最新的: ruby -v
  • Update gem's sudo gem update --system更新 gem 的sudo gem update --system

2. Set Up MAC Environment 2.设置MAC环境

Install the Xcode Command Line Tools this is the key to install Compass.安装Xcode Command Line Tools这是安装 Compass 的关键。

xcode-select --install

Installing the Xcode Command Line Tools are the key to getting Compass working on OS X安装 Xcode 命令行工具是让 Compass 在 OS X 上工作的关键

3. Install Compass 3.安装指南针

sudo gem install compass

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

You can try in Debian with你可以在 Debian 中尝试

sudo apt-get install gcc ruby-dev rubygems compass

for Fedora, Centos用于 Fedora、Centos

yum -y install gcc ruby-devel rubygems compass

It worked for me.它对我有用。

I struggled with you same issue for about 3 hours.我与你同样的问题挣扎了大约 3 个小时。 As of Compass 1.0.alpha19 , the requirement is for the rvm version 1.9.3.Compass 1.0.alpha19 ,要求是 rvm 版本 1.9.3。

There are several uncollected posts, however what worked for me was the following:有几个未收集的帖子,但是对我有用的是以下内容:

  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

and that did it.做到了。 Hope it works for you as well!希望它也适用于您!

For me to solve this issue, I had to make sure I had the most current version of Ruby and the gems gem update --system ;为了解决这个问题,我必须确保我拥有最新版本的 Ruby 和 gems gem update --system then, I had to make sure that Xcode & the Command Line Tools were installed: xcode-select --install .然后,我必须确保安装了 Xcode 和命令行工具: xcode-select --install

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

xcode-select --install

Hi it was a challenge to get it work on Mac so anyway here is a solution嗨,让它在 Mac 上工作是一个挑战,所以无论如何这里是一个解决方案

  1. Install macports安装macports
  2. Install rvm安装rvm
  3. Restart Terminal重启终端
  4. Run rvm requirements then run rvm install 2.1运行rvm requirements然后运行rvm install 2.1
  5. And last step to run gem install compass --pre最后一步运行gem install compass --pre

I'm not sure but ruby version on Mavericks doesn't support native extensions etc... so if you point to other ruby version like I did "2.1" it works fine.我不确定,但 Mavericks 上的 ruby​​ 版本不支持本机扩展等......所以如果你指向其他 ruby​​ 版本,就像我做的“2.1”一样,它工作正常。

Not sure why none of these are marked as the correct answer, but I landed here through a google search, so I will pass along what I know...不知道为什么这些都没有被标记为正确答案,但我是通过谷歌搜索来到这里的,所以我会传递我所知道的......

@paul_g's method was pretty close for me, my steps on a Mac osx10.9 Retina: @paul_g 的方法对我来说非常接近,我在 Mac osx10.9 Retina 上的步骤:

  • Install macports安装macports
  • Install rvm (stable with ruby add --insecure flag for SSL related issues) $ \\curl -sSL --insecure https://get.rvm.io | bash -s stable --ruby安装 rvm(稳定与 ruby​​ 为 SSL 相关问题添加--insecure标志) $ \\curl -sSL --insecure https://get.rvm.io | bash -s stable --ruby \\curl -sSL --insecure https://get.rvm.io | bash -s stable --ruby
  • Restart Terminal / Resource your profile重新启动终端/资源您的个人资料
  • Run rvm requirements --with-gcc=clang You won't have to update Ruby because you downloaded the last stable version运行rvm requirements --with-gcc=clang你不必更新 Ruby 因为你下载了最后一个稳定版本
  • And last step to run gem install compass --pre最后一步运行gem install compass --pre

If you are using Ubuntu, you should try install build-essential如果您使用的是 Ubuntu,您应该尝试安装 build-essential

apt install build-essential

I had troubles with gems installation on fresh installation of ubuntu, and this solution worked for me.我在全新安装 ubuntu 时遇到了 gems 安装问题,这个解决方案对我有用。

You could need to install Apple's Command Line Tools, which probably aren't installed on your system by default.您可能需要安装 Apple 的命令行工具,默认情况下您的系统上可能未安装该工具。 I was getting the same error, but before following any of the instructions here I installed Command Line Tools (due to an unrelated issue) and lo and behold compass installed without issue when I tried again.我遇到了同样的错误,但在按照此处的任何说明进行操作之前,我安装了命令行工具(由于一个不相关的问题),并且当我再次尝试时,发现指南针安装没有问题。 YMMV.天啊。

In order to install Compass on Yosemite you need to set up the Ruby environment and to install the Xcode Command Line Tools.为了在 Yosemite 上安装 Compass,您需要设置 Ruby 环境并安装 Xcode 命令行工具。 But, most important thing, after updating Xcode, be sure to launch the Xcode application and accept the Apple license terms .但是,最重要的是,在更新 Xcode 后,请务必启动 Xcode 应用程序并接受 Apple 许可条款 It will complete the installation of the components.它将完成组件的安装。 After that, you can install Compass: sudo gem install compass之后,您可以安装指南针: sudo gem install compass

For Mac OS:对于 Mac 操作系统:

My error was I forgot to select option in XCode - Preferences - Locations - Command Line Tools after new XCode installation (I had 2 versions and later I deleted one).我的错误是我忘记在新 XCode 安装后选择 XCode - 首选项 - 位置 - 命令行工具中的选项(我有 2 个版本,后来我删除了一个)。 Maybe it will help someone.也许它会帮助某人。

在此处输入图片说明

For macOS 10.14 Mojave, make sure you have already installed command line tools via xcode-select --install and the run the following command to install std headers.对于 macOS 10.14 Mojave,请确保您已经通过xcode-select --install安装了命令行工具,并运行以下命令来安装 std 头文件。

sudo open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

Now try your command again.现在再次尝试您的命令。

sudo gem update --system
sudo gem install compass 

you must have gcc,json_pure你必须有gcc,json_pure

i collect some information from several post我从几个帖子中收集了一些信息

 sudo gem uninstall sass sudo gem uninstall compass sudo gem update --system gem install json_pure (if you have already have continued to next step) sudo yum install gcc gcc-c++ (if you have already have continued to next step) sudo gem install sass sudo gem install compass

Hi if ** sudo gem update --system ** not working you got an error in the update then use嗨,如果 ** sudo gem update --system ** 不工作,您在更新中遇到错误,然后使用

sudo gem update --system 2.7.8须藤宝石更新 --system 2.7.8

On yosemite, all you must do is install the command line tools.在优胜美地,您必须做的就是安装命令行工具。 then it works.那么它的工作原理。

Even if other gems installed fine.即使其他 gems 安装得很好。 You must run xcode-select --install for gem install compass to work.您必须运行 xcode-select --install 才能让 gem install compass 工作。

Good luck.祝你好运。

On Mac OS X 10.9, if you try xcode-select --install , you will get the following error :在 Mac OS X 10.9 上,如果您尝试xcode-select --install ,您将收到以下错误:

Can't install the software because it is not currently available from the Software Update server.无法安装该软件,因为软件更新服务器当前不提供该软件。

The solution is to download Command Line Tools (OS X 10.9) directly from Apple website : https://developer.apple.com/downloads/index.action?name=for%20Xcode%20-解决方案是直接从 Apple 网站下载命令行工具 (OS X 10.9): https : //developer.apple.com/downloads/index.action?name=for%20Xcode%20-

You will then be able to install the last version of Command Line Tools.然后,您将能够安装最新版本的命令行工具。

In ubuntu 14.04, while execute apt-get install rubygems , there is a error在 ubuntu 14.04 中,执行apt-get install ruby​​gems时出现错误

E: Package 'rubygems' has no installation candidate E: 包 'rubygems' 没有安装候选

follow command solve the problems.按照命令解决问题。

sudo apt-get install gcc ruby-devel rubygems-integration ruby-compass sudo apt-get install gcc ruby​​-devel ruby​​gems-integration ruby​​-compass

Try brew install coreutils .尝试brew install coreutils

I've hit this problem while rebuilding an aging sass/compass project that was recently updated to ruby 2.2.5 by a colleague.我在重建一个老旧的 sass/compass 项目时遇到了这个问题,该项目最近被一位同事更新为 ruby​​ 2.2.5。 The project uses rvm and bundler.该项目使用 rvm 和 bundler。 These were my commands这些是我的命令

$ rvm install ruby-2.2.5
$ rvm use ruby-2.2.5
$ gem install bundler
$ bundle install

This caused me to hit the famed ffi installation errors, that are reported around the StackOverflow environment:这导致我遇到了著名的ffi安装错误,这些错误是在 StackOverflow 环境中报告的:

An error occurred while installing ffi (1.9.14), and Bundler cannot continue.

Most of the suggestions to solve this problem are to install Xcode command line tools.大多数解决这个问题的建议是安装 Xcode 命令行工具。 However this was already installed in my environment:但是,这已经安装在我的环境中:

$ xcode-select -p
/Library/Developer/CommandLineTools

Other suggestions said to install gcc... so I tried:其他建议说安装 gcc ......所以我试过:

$ brew install gcc46

But this also failed due to a segmentation fault... ¯\\_(ツ)_/¯ .但这也由于分段错误而失败...... ¯\\_(ツ)_/¯

So, I then tried installing compass by hand, just to see if it would give the same ffi error:所以,我然后尝试手动安装指南针,只是为了看看它是否会给出相同的ffi错误:

$ gem install compass

But to my surprise, I got a totally different error:但令我惊讶的是,我得到了一个完全不同的错误:

make: /usr/local/bin/gmkdir: No such file or directory

So I searched for that issue, and found this ancient blog post that said to install coreutils:所以我搜索了这个问题,并找到了这篇古老的博客文章,上面写着要安装 coreutils:

$ brew install coreutils

After installing coreutils with Homebrew, bundler was able to finish and installed compass and dependencies successfully.使用 Homebrew 安装coreutils后,bundler 能够成功完成并安装指南针和依赖项。

The End.结束。

when什么时候

gem install overcommit gem安装过量使用

is run also this error have been placed in terminal.运行此错误也已放置在终端中。

Failed to build gem native extension

please do the same请做同样的事情

xcode-select --install

and it will fix that issue too它也会解决这个问题

试试这个,然后再次尝试安装指南针

sudo apt install ruby-full

I had the same problem on Linux Mint but I was able to fix it by uninstalling ruby and install it again.我在 Linux Mint 上遇到了同样的问题,但我能够通过卸载 ruby​​ 并重新安装来修复它。

Uninstall ruby:卸载红宝石:

sudo apt-get remove ruby

It reported some ruby packages like:它报告了一些 ruby​​ 包,例如:

Package 'ruby' is not installed, so not removed
The following packages were automatically installed and are no longer required:
libruby2.2 ruby-chunky-png ruby-sass rubygems-integration
Use 'apt-get autoremove' to remove them.

Uninstall remaining packages*卸载剩余的软件包*

apt-get autoremove

Install ruby again再次安装红宝石

sudo apt-get install ruby2.2

Install Compass安装指南针

sudo gem install compass

The last command was executed with success.最后一条命令执行成功。

Installing Ruby gems on a Mac is a common source of confusion and frustration.在 Mac 上安装 Ruby gems 是一个常见的困惑和挫折来源。 Unfortunately, most solutions are incomplete, outdated, and provide bad advice.不幸的是,大多数解决方案都不完整、过时并且提供了糟糕的建议。 The answer here with the most votes says to use sudo which you should never need to do, especially if you don't understand what it does.此处得票最多的答案是使用sudo ,您永远不需要这样做,尤其是当您不了解它的作用时。

It is correct that the error "Failed to build gem native extension" is due to the Apple command line tools not being installed.错误“Failed to build gem native extension”是由于没有安装Apple命令行工具是正确的。 However, installing them won't necessarily provide you with a proper Ruby environment.但是,安装它们不一定会为您提供合适的 Ruby 环境。 There are 5 steps to a working Ruby setup, which I've written about in a lot of detail in my definitive guide to installing Ruby gems on a Mac .安装 Ruby 需要 5 个步骤,我在我在 Mac 上安装 Ruby gems 的权威指南中详细介绍了这些步骤 It explains why you are getting this error, compares the various solutions, why some are better than others, and why you shouldn't use sudo .它解释了为什么会出现此错误,比较了各种解决方案,为什么有些解决方案比其他解决方案更好,以及为什么不应该使用sudo

TL;DR: Use a battle-tested and reliable automated script that will set everything up for you: https://github.com/monfresh/laptop TL;DR:使用经过实战测试且可靠的自动化脚本,为您设置一切: https : //github.com/monfresh/laptop

First had to upgrade from Ruby 2.6 to 3.0 (see https://rvm.io/ ):首先必须从 Ruby 2.6 升级到 3.0(参见https://rvm.io/ ):

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

Then I had to install it in local because otherwise Mac OSX permissions won`t let me upgrade it (see ERROR: While executing gem... (Errno::EPERM) Operation not permitted ):然后我不得不在本地安装它,否则 Mac OSX 权限不允许我升级它(请参阅错误:执行 gem 时... (Errno::EPERM) 不允许操作):

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

I am not totally sure if installing rvm above first was necessary, but it was useful for upgrading ruby.我不确定是否需要先安装上面的rvm ,但它对升级 ruby 很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM