Failed to build gem native extension (installing Compass)

RubyMacosTerminalCompass Sass

Ruby Problem Overview


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.

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?

Ruby Solutions


Solution 1 - Ruby

Try this, then try to install compass again

apt-get install ruby-dev

Solution 2 - Ruby

In order to install compass On Mac OS X 10.10 (Yosemite)had to perform the following:

1. Set Up Ruby Environment

  • Ensure ruby is installed and up to date: ruby -v
  • Update gem's sudo gem update --system

2. Set Up MAC Environment

Install the Xcode Command Line Tools this is the key to install Compass.

xcode-select --install

Installing the Xcode Command Line Tools are the key to getting Compass working on OS X

3. Install Compass

sudo gem install compass

Solution 3 - Ruby

The best way is sudo apt-get install ruby-compass to install compass.

Solution 4 - Ruby

You can try in Debian with

sudo apt-get install gcc ruby-dev rubygems compass

for Fedora, Centos

yum -y install gcc ruby-devel rubygems compass

It worked for me.

Solution 5 - Ruby

I struggled with you same issue for about 3 hours. As of Compass 1.0.alpha19, the requirement is for the rvm version 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!

Solution 6 - Ruby

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; then, I had to make sure that Xcode & the Command Line Tools were installed: xcode-select --install.

Solution 7 - Ruby

On Mac OS you need to install this feature!

xcode-select --install

Solution 8 - Ruby

Hi it was a challenge to get it work on Mac so anyway here is a solution

  1. Install macports
  2. Install rvm
  3. Restart Terminal
  4. Run rvm requirements then run rvm install 2.1
  5. And last step to run 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.

Solution 9 - Ruby

If you are using Ubuntu, you should try install build-essential

apt install build-essential

I had troubles with gems installation on fresh installation of ubuntu, and this solution worked for me.

Solution 10 - Ruby

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:

  • Install macports
  • Install rvm (stable with ruby add --insecure flag for SSL related issues) $\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
  • And last step to run gem install compass --pre

Solution 11 - Ruby

sudo gem update --system
sudo gem install compass 

Solution 12 - Ruby

For Mac OS:

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). Maybe it will help someone.

enter image description here

Solution 13 - Ruby

You could need to install Apple's Command Line Tools, which probably aren't installed on your system by default. 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.

Solution 14 - Ruby

In order to install Compass on Yosemite you need to set up the Ruby environment and to install the Xcode Command Line Tools. But, most important thing, after updating Xcode, be sure to launch the Xcode application and accept the Apple license terms. It will complete the installation of the components. After that, you can install Compass: sudo gem install compass

Solution 15 - Ruby

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.

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

Now try your command again.

Solution 16 - Ruby

you must have 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 2.7.8

Solution 17 - Ruby

On yosemite, all you must do is install the command line tools. then it works.

Even if other gems installed fine. You must run xcode-select --install for gem install compass to work.

Good luck.

Solution 18 - Ruby

On Mac OS X 10.9, if you try xcode-select --install, you will get the following error :

> 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-

You will then be able to install the last version of Command Line Tools.

Solution 19 - Ruby

In ubuntu 14.04, while execute apt-get install rubygems, there is a error

> E: Package 'rubygems' has no installation candidate

follow command solve the problems.

> sudo apt-get install gcc ruby-devel rubygems-integration ruby-compass

Solution 20 - Ruby

Try 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. The project uses rvm and 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:

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. However this was already installed in my environment:

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

Other suggestions said to install gcc... so I tried:

$ 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:

$ 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:

$ brew install coreutils

After installing coreutils with Homebrew, bundler was able to finish and installed compass and dependencies successfully.

The End.

Solution 21 - Ruby

when

> gem install overcommit

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

Solution 22 - Ruby

Try this, then try to install compass again

sudo apt install ruby-full

Solution 23 - Ruby

I had the same problem on Linux Mint but I was able to fix it by uninstalling ruby and install it again.

Uninstall ruby:

sudo apt-get remove ruby

It reported some ruby packages like:

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.

Solution 24 - Ruby

First had to upgrade from Ruby 2.6 to 3.0 (see 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 https://stackoverflow.com/questions/32891965/error-while-executing-gem-errnoeperm-operation-not-permitted):

$ 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.

Solution 25 - Ruby

Installing Ruby gems on a Mac is a common source of confusion and frustration. 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.

Learn why you should never use sudo to install gems.

It is correct that the error "Failed to build gem native extension" is due to the Apple command line tools not being installed. However, installing them won't necessarily provide you with a proper Ruby environment.

At a high level, there are 5 steps to a working Ruby setup, which I've written about in detail in my definitive guide to installing Ruby gems on a Mac. 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.

I've also written about these steps in this answer: https://stackoverflow.com/a/54873916/928191

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioncusejuiceView Question on Stackoverflow
Solution 1 - RubyRutger van BarenView Answer on Stackoverflow
Solution 2 - RubyneteruView Answer on Stackoverflow
Solution 3 - Rubycooljl31View Answer on Stackoverflow
Solution 4 - Rubyvanduc1102View Answer on Stackoverflow
Solution 5 - RubyA. A. Trabucco CamposView Answer on Stackoverflow
Solution 6 - RubyBlackHatSamuraiView Answer on Stackoverflow
Solution 7 - RubyalvescleitonView Answer on Stackoverflow
Solution 8 - Rubypaul.gView Answer on Stackoverflow
Solution 9 - RubyAdrianView Answer on Stackoverflow
Solution 10 - RubytbremerView Answer on Stackoverflow
Solution 11 - RubyFederico BohnView Answer on Stackoverflow
Solution 12 - RubyEridanaView Answer on Stackoverflow
Solution 13 - RubyJohn RyanView Answer on Stackoverflow
Solution 14 - RubyGratzView Answer on Stackoverflow
Solution 15 - RubyVincent SitView Answer on Stackoverflow
Solution 16 - RubygsmView Answer on Stackoverflow
Solution 17 - RubyA.Sanchez.SDView Answer on Stackoverflow
Solution 18 - RubylepixView Answer on Stackoverflow
Solution 19 - RubyonebravemanView Answer on Stackoverflow
Solution 20 - RubyJamesWilsonView Answer on Stackoverflow
Solution 21 - RubyAnja IshmukhametovaView Answer on Stackoverflow
Solution 22 - RubyPokkhiView Answer on Stackoverflow
Solution 23 - Rubyclaudiu.f.margineanView Answer on Stackoverflow
Solution 24 - Rubyuser8128167View Answer on Stackoverflow
Solution 25 - RubymonfreshView Answer on Stackoverflow