[ruby] 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.

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?

This question is related to ruby macos terminal compass-sass

The answer is


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.


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

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.

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

TL;DR: Use a battle-tested and reliable automated script that will set everything up for you: https://github.com/monfresh/laptop


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.


Try this, then try to install compass again

sudo apt install ruby-full

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.


you must have gcc,json_pure

i collect some information from several post

_x000D_
_x000D_
sudo gem uninstall sass_x000D_
sudo gem uninstall compass_x000D_
sudo gem update --system_x000D_
gem install json_pure   (if you have already have continued to next step)_x000D_
sudo yum install gcc gcc-c++   (if you have already have continued to next step)_x000D_
sudo gem install sass_x000D_
_x000D_
sudo gem install compass
_x000D_
_x000D_
_x000D_

Hi if ** sudo gem update --system ** not working you got an error in the update then use

sudo gem update --system 2.7.8


On Mac OS you need to install this feature!

xcode-select --install

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


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.


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


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


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.


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.


sudo gem update --system
sudo gem install compass 

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


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.


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!


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

Try this, then try to install compass again

apt-get install ruby-dev

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


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.


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.


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.


Examples related to ruby

Uninitialized Constant MessagesController Embed ruby within URL : Middleman Blog Titlecase all entries into a form_for text field Ruby - ignore "exit" in code Empty brackets '[]' appearing when using .where find_spec_for_exe': can't find gem bundler (>= 0.a) (Gem::GemNotFoundException) How to update Ruby Version 2.0.0 to the latest version in Mac OSX Yosemite? How to fix "Your Ruby version is 2.3.0, but your Gemfile specified 2.2.5" while server starting Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? How to update Ruby with Homebrew?

Examples related to macos

Problems with installation of Google App Engine SDK for php in OS X dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib error running php after installing node with brew on Mac Could not install packages due to an EnvironmentError: [Errno 13] How do I install Java on Mac OSX allowing version switching? Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) Can't compile C program on a Mac after upgrade to Mojave You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory. (mac user) How can I install a previous version of Python 3 in macOS using homebrew? Could not install packages due to a "Environment error :[error 13]: permission denied : 'usr/local/bin/f2py'"

Examples related to terminal

Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) Can't compile C program on a Mac after upgrade to Mojave Flutter command not found VSCode Change Default Terminal How to switch Python versions in Terminal? How to open the terminal in Atom? Color theme for VS Code integrated terminal How to edit a text file in my terminal How to open google chrome from terminal? Switch between python 2.7 and python 3.5 on Mac OS X

Examples related to compass-sass

SASS :not selector Failed to build gem native extension (installing Compass) File to import not found or unreadable: compass