ERROR: Error installing ffi: ERROR: Failed to build gem native extension - ruby

Got the DevKit installed and re-ran the ffi install….got this as an output:
C:\Documents and Settings\******>gem install ffi
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing ffi:
ERROR: Failed to build gem native extension.
C:/Ruby192/bin/ruby.exe extconf.rb
checking for ffi.h... no
checking for ffi.h in /usr/local/include... no
checking for rb_thread_blocking_region()... yes
checking for ruby_thread_has_gvl_p()... yes
checking for ruby_native_thread_p()... yes
checking for rb_thread_call_with_gvl()... yes
creating extconf.h
creating Makefile
make
C:/Ruby192/bin/ruby -e "puts 'EXPORTS', 'Init_ffi_c'" > ffi_c-i386-mingw32.def
gcc -I. -IC:/Ruby192/include/ruby-1.9.1/i386-mingw32 -I/C/Ruby192/include/ruby-1
.9.1/ruby/backward -I/C/Ruby192/include/ruby-1.9.1 -I. -DRUBY_EXTCONF_H=\"extcon
f.h\" -O3 -g -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -
Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-declaration-a
fter-statement -o AbstractMemory.o -c AbstractMemory.c
In file included from AbstractMemory.c:28:0:
compat.h:65:20: warning: extra tokens at end of #ifndef directive
compat.h:69:24: warning: extra tokens at end of #ifndef directive
In file included from AbstractMemory.h:29:0,
from AbstractMemory.c:29:
Types.h:68:17: fatal error: ffi.h: No such file or directory
compilation terminated.
make: *** [AbstractMemory.o] Error 1
Gem files will remain installed in C:/Ruby192/lib/ruby/gems/1.9.1/gems/ffi-1.0.1
0 for inspection.
Results logged to C:/Ruby192/lib/ruby/gems/1.9.1/gems/ffi-1.0.10/ext/ffi_c/gem_m
ake.out
_________________________________________________________________________________
Not sure how to deal with this issue. Kindly help.

The gem install ffi fails due to the gem trying to build a bundled copy of libffi, which does not work due to assumptions that /usr/bin/env exists and too old libffi copy.
However, you can build the ffi gem against the system libffi - install the packages:
apt install clang make ruby-dev libffi-dev
After that the ffi gem should build:
gem install ffi

Version 1.0.10 has issues compiling on windows.
You can use the 1.0.9
gem install ffi --version='1.0.9'

sudo apt-get install libffi-dev
This worked for me

For me the fix was running in this order. I'm not sure what all was relevant, but it worked:
gem install ffi --version '1.0.9'
The above failed, but then I could successfully run:
gem install bundler
...and subsequently:
gem install ffi
...which got the latest version (1.6.0 at the time of writing this) and installed it successfully.

Note that installing version 1.0.9 isn't going to be enough if your bundler keeps trying to go out and grab the latest version. In your gemfile you'll also want to put:
gem 'ffi', '1.0.9'
This should satisfy the dependency for whatever gem is asking for it and let you get up and running.

when the above steps are followed, it might results the following message.
$ bundle install
Fetching source index for https://rubygems.org/
You have requested:
ffi = 1.0.9
The bundle currently has ffi locked at 1.0.11.
Try running `bundle update ffi`
In that case, you can run the 'bundle update ffi' command and the error will be solved.

Installing the 'osx-gcc-installer' worked for me: (osx 10.8)
https://github.com/kennethreitz/osx-gcc-installer/downloads

Helped me:
sudo apt install build-essential
Debian 9
Ruby 2.3.3

you need this,
apt-get install ruby2.2-dev

Copied from another post:
As stated in Issue with installing ImageMagick and rmagick on Mountain Lion, ffi appears to be configured to look for 'gcc-4.2', so once I updated my Apple command line tools (which I may or may not have needed to do), I created a symbolic link to make the ffi install configuration happy:
sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2

For me, this usually works
gem install ffi -- --disable-system-libffi

On MacOS (Catalina), running brew install libtool first solved the problem for me.

This worked for me
gem install ffi -- --disable-system-libffi
on Ubuntu 20.04 (WSL)

Put DevKit in front of your PATH, and install again from Windows command prompt.

I got the same problem. In my case, I have not install the DevKit, which can be found: http://rubyinstaller.org/downloads/. After installing DevKit, just follow the instruction https://github.com/oneclick/rubyinstaller/wiki/development-kit and finally it's up and running.

I had to install automake to get it working. Worked on both mac OSX as well as Ubuntu (CI machine).

Run this: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Then: brew install cocoapods

Related

gem install compass won't work

When I try to install compass using sudo gem install compass it show me this :
Building native extensions. This could take a while...
ERROR: Error installing compass:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -r ./siteconf20141125-86718-gjziv3-0.rb extconf.rb
checking for ffi.h... no
checking for ffi.h in /usr/local/include,/usr/include/ffi... no
checking for rb_thread_blocking_region()... no
checking for rb_thread_call_with_gvl()... no
checking for rb_thread_call_without_gvl()... no
checking for ffi_prep_cif_var()... no
creating extconf.h
creating Makefile
make clean
make
mkdir -p "/Library/Ruby/Gems/1.8/gems/ffi-1.9.6/ext/ffi_c"/libffi-i386; (if [ ! -f "/Library/Ruby/Gems/1.8/gems/ffi-1.9.6/ext/ffi_c"/libffi-i386/Makefile ]; then echo "Configuring libffi for i386"; cd "/Library/Ruby/Gems/1.8/gems/ffi-1.9.6/ext/ffi_c"/libffi-i386 && env CC=" xcrun cc" CFLAGS="-arch i386 " LDFLAGS="-arch i386" "/Library/Ruby/Gems/1.8/gems/ffi-1.9.6/ext/ffi_c/libffi"/configure --disable-static --with-pic=yes --disable-dependency-tracking --host=i386-apple-darwin > /dev/null; fi); env MACOSX_DEPLOYMENT_TARGET=10.4 make -C "/Library/Ruby/Gems/1.8/gems/ffi-1.9.6/ext/ffi_c"/libffi-i386
Configuring libffi for i386
configure: WARNING: if you wanted to set the --build type, don't use --host.
If a cross compiler is detected then cross compile mode will be used
configure: error: in `/Library/Ruby/Gems/1.8/gems/ffi-1.9.6/ext/ffi_c/libffi-i386':
configure: error: C compiler cannot create executables
See `config.log' for more details
make[1]: *** No targets specified and no makefile found. Stop.
make: *** ["/Library/Ruby/Gems/1.8/gems/ffi-1.9.6/ext/ffi_c"/libffi-i386/.libs/libffi_convenience.a] Error 2
make failed, exit code 2
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/ffi-1.9.6 for inspection.
Results logged to /Library/Ruby/Gems/1.8/extensions/universal-darwin-11/1.8/ffi-1.9.6/gem_make.out
I have correctly install sass and xcode' tools but nothing change. I even try to upgrade ruby. What should I do?
It happens because you want to sudo install and probably environment variables are not configured to use your installed ruby, instead it uses the system ruby which probably is not what you want to use.
The easiest way to use Ruby on Mac is to install rbenv and ruby-build using homebrew.
To install homebrew just run this command which can be found on brew homepage:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
To install rbenv and ruby-build you can run these commands which can be found on Github:
brew update
brew install rbenv ruby-build
Forgot to add that for sure, then you need to install a ruby version using rbenv and make it global.
rbenv install 2.1.5
rbenv global 2.1.5
And finally:
gem install compass
Just make sure that gem binary points to the version you've installed.
You can run gem env and checkout printed paths, if it doesn't point to newly installed ruby gem path, close the terminal and open a new one then install the gem.
Here is the first few lines of what's printed out on my machine:
RubyGems Environment:
- RUBYGEMS VERSION: 2.2.0
- RUBY VERSION: 2.1.0 (2013-12-25 patchlevel 0) [x86_64-darwin13.0]
- INSTALLATION DIRECTORY: /Users/jani/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0
....

Nokogiri gem fails to install in OS X Mavericks

Install fails showing:
checking for iconv_open() in iconv.h... no
checking for iconv_open() in -liconv... no
checking for iconv_open() in -liconv... no
checking for libiconv_open() in iconv.h... no
checking for libiconv_open() in -liconv... no
checking for libiconv_open() in -liconv... no
libiconv is missing.
However, looking at nokogiri's mkmf.log, the following errors are shown:
ld: warning: ignoring file /usr/local/Cellar/libxslt/1.1.28/lib/libxslt.dylib, **file was built for x86_64 which is not the architecture being linked (i386)**: /usr/local/Cellar/libxslt/1.1.28/lib/libxslt.dylib
ld: warning: ignoring file /usr/local/Cellar/libxml2/2.9.1/lib/libxml2.dylib, **file was built for x86_64 which is not the architecture being linked (i386)**: /usr/local/Cellar/libxml2/2.9.1/lib/libxml2.dylib
ld: warning: ignoring file /usr/local/Cellar/libiconv/1.14/lib/libiconv.dylib, **file was built for x86_64 which is not the architecture being linked (i386)**: /usr/local/Cellar/libiconv/1.14/lib/libiconv.dylib
I have xcode and it's command tools installed.
My ~/.bash_profile has 64bit compiling forced by: export ARCHFLAGS="-arch x86_64"
I have libxml2, libxslt, and libiconv installed via Homebrew, and each is linked.
I've tried installing all of these without the ARCHFLAG in .bash_profile.
I've also brew install apple-gcc42 and linked, as per how tos I've found.
I've tried installing nokogiri by passing paths to libxml2, libxslt, and libiconv in /usr/local/Cellar/, but the install still fails, with same errors as above.
I've wasted at least a day on this - just trying to get one Ruby gem installed. I'd really like to get back to actually developing.
Can anyone please help?
Setting NOKOGIRI_USE_SYSTEM_LIBRARIES=1 before actually installing the gem did the trick for me.
Summarising:
If previously installed, uninstall the gem:
$ gem uninstall nokogiri
Use Homebrew to install libxml2, libxslt and libiconv if needed:
$ brew install libxml2 libxslt libiconv
Install the gem specifying the paths to the libraries to be linked against:
$ NOKOGIRI_USE_SYSTEM_LIBRARIES=1 gem install nokogiri -- --use-system-libraries --with-iconv-dir="$(brew --prefix libiconv)" --with-xml2-config="$(brew --prefix libxml2)/bin/xml2-config" --with-xslt-config="$(brew --prefix libxslt)/bin/xslt-config"
Check if HomeBrew is installed correctly with the appropriate XCode command line tools.
brew doctor
You can also check via XCode > Preferences
With valid command line tools installed, I was able to resolve the nokogiri error encountered after the OSX Maverick upgrade.
Also found that some of the 'brew' packages were outdated after the OS X Mountain Lion to Maverick upgrade. (e.g. qt, postgresql)
Here's what worked for me:
If you haven't already done so, install the XCode developer tools: $ xcode-select --install
Use homebrew to install (or reinstall) libxml2, libxslt and libiconv: $ brew install libxml2 libxslt libiconv
Install nokogiri: gem install nokogiri -- --with-iconv-dir=/usr/local/opt/libiconv
I found the solution I needed in an unmerged pull request to update the Nokogiri tutorials. I recommend that if someone else encounters this issue and has exhausted the solutions here, check that pull request list to see if someone has submitted an update to the instructions on the Nokogiri tutorials page.
From github page
First, you should:
xcode-select --install
and then re-install nokogiri.
That worked for me while another suggestion didn't. Hope this helps someone else.

How to install Nokogiri Ruby gem with mkmf.log saying libiconv not found?

I'm installing the Ruby Nokogiri gem and finding the error below.
How to diagnose this and solve it?
# gem install nokogiri
Building native extensions. This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
...
/opt/ruby/1.9.3-p194/bin/ruby extconf.rb
checking for libxml/parser.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
...
/opt/ruby/1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:381:in `try_do':
The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /opt/ruby/1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:506:in `try_cpp'
...
To diagnose and solve, here's what worked for me.
To find out what failed, go to your ruby gems directory.
For example:
$ cd <MY RUBY DIRECTORY>/lib/ruby/gems/2.0.0/gems
If you don't know your gem directory, try this:
$ echo $GEM_HOME
/opt/gems/2.0.0
$ cd /opt/gems/2.0.0/gems
What version of nokogiri am I installing?
$ ls -ladg nokogiri-*
nokogiri-1.5.5
Go to the installer directory:
$ cd nokogiri-1.5.5/ext/nokogiri
Try installing manually:
$ ruby extconf.rb
Result:
checking for libxml/parser.h... *** extconf.rb failed ***
...
I'm using Ubuntu so I search for any similar packages:
$ aptitude search libxml
Results:
p libxml2 - GNOME XML library
p libxml2-dev - Development files for the GNOME XML library
...
I believe that libxml2 will work fine.
$ apt-get install libxml2
Ruby native gems often need the *-dev packages for headers so install them:
$ apt-get install libxml2-dev
Now do I have the parser file?
$ find / | grep libxml/parser.h
Yes, the result shows the parser:
/usr/include/libxml2/libxml/parser.h
Now try installing again, this time providing the libxml2 path:
$ gem install nokogiri -- --with-xml2-dir=/usr/include/libxml2
It still fails, so read the mkmf error log:
$ more mkmf.log
The error log shows what failed and has these lines that look promising:
package configuration for libxslt is not found
Is there a package for it?
$ aptitude search libxslt
Results:
v libxslt-dev
i libxslt-ruby
...
Install the dev package:
$ apt-get install libxslt-dev
Now try installing again, and also put xslt on the path:
$ gem install nokogiri -- \
--with-xml2-dir=/usr/include/libxml2 \
--with-xslt-dir=/usr/include/libxslt
Success!
Installing Nokogiri Website
'Installing Nokogiri' is a website dedicated to installing Nokogiri on the major platforms - Here is an excerpt about Installing Nokogiri on Ubuntu:
Because Nokogiri needs to be compiled and dynamically linked against
both libxml2 and libxslt, it has gained a reputation for being
complicated to install.
As of Nokogiri 1.6, libxml2 and libxslt source code is bundled with
Nokogiri, and compiled at gem-install-time. The instructions in this
document should work for all versions 1.6.4 and later.
Ubuntu / Debian
Installation should Just Work™ on Ubuntu and Debian using Nokogiri’s
vendored libxml2 and libxslt:
gem install nokogiri
[...]
Using Your System Libraries
If, instead of Nokogiri’s vendored libraries, you’d like to use your
system’s libxml2, libxslt and related libraries, please first
understand that you may be asking Nokogiri to work with an unsupported
version of libxml2.
sudo apt-get install pkg-config
gem install nokogiri -- --use-system-libraries
FYI - I am using Nokogiri 1.6.6.2 and it didn't 'just work'. I got it going with the --use-system-libraries.
Mac OS X
The website's advice also covers OS X - this worked for me:
gem update --system
xcode-select --install
gem install nokogiri
Conclusion
If you have a Nokogiri problem on any platform you should check out the website.
On CentOS here is what I needed to do:
gem update --system
yum install libxml2-devel libxslt-devel ruby-devel
gem install nokogiri -- --use-system-libraries
Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers.
You are probably missing zlib headers which are required for -lz flag in order to compile the sources correctly. Install on Linux by:
sudo apt-get install libz-dev
For missing libiconv, try installing libiconv-hook-dev package which has header files of libiconv-hook, e.g.
sudo apt-get install libiconv-hook1 libiconv-hook-dev
On OS X, try installing development tools via: xcode-select --install.
If there is still problem, check mkmf.log file for more specific details about your error.
On Ubuntu, try the following dependency fix combo:
sudo apt-get install gcc ruby-dev libxslt-dev libxml2-dev zlib1g-dev
The 'could not create Makefile' error you're seeing could also be because you haven't agreed to the Xcode license (you have to agree to it after each time you update Xcode). Running sudo xcodebuild -license accept should eliminate this error for you and allow you to then run gem install nokogiri successfully.

Problems getting ruby-libvirt extensions to compile Mountain Lion

I bought a new Mac this week and have had big problems getting this gem installed. It was never a problem on my old Mac but seems to be particularly difficult on this one.
I have installed libvirt via Homebrew, Xcode4.4 (with command line tools) and gcc4.2. I have symlinked to make gcc4.2 the default compiler.
gem install ruby-libvirt -v '0.4.0' fails because it cannot find the headers
If I pass in the paths to the headers and libraries, like so:
ruby-libvirt -v '0.4.0' -V -- --with-libvirt-include=/usr/local/Cellar/libvirt/0.9.11.3/include/ --with-libvirt-lib=/usr/local/Cellar/libvirt/0.9.11.3/lib/
, it compiles just fine but fails when linking with the following errors:
linking shared-object _libvirt.bundle
ld: library not found for -lruby.1.9.1
collect2: ld returned 1 exit status
make: *** [_libvirt.bundle] Error 1
I have installed Ruby 1.9.3 via RVM and haven't had any troubles installing other native extensions, so I cannot see why it fails to find the ruby libraries in this case.
Does anyone have any ideas? Help would be much appreciated.
I built ruby-libvirt-0.4.0/ext/libvirt by proving external libvirt installed using brew.
Here is what I did to successfully install libvirt.
brew install libvirt
ruby extconf.rb --with-libvirt-include=/usr/local/include/libvirt --with-libvirt-lib=/usr/local/lib/libvirt
gem install ruby-libvirt -v '0.4.0' -V -- --with-libvirt-include=/usr/local/Cellar/libvirt/1.1.4/include/libvirt --with-libvirt-lib=/usr/local/Cellar/libvirt/1.1.4/lib
Hope this helps.
To install the gem you need to install the libvirt libraries. Using 'Homebrew' (a package manager for mac) :
brew install libvirt
bundle install
The exact error you got might have been:
An error occurred while installing ruby-libvirt (0.4.0)
I have finally solved this. It turns out that the command line tools were not properly installed. The following line needs to be added to your .zshrc file (or whatever applies to your choice of shell):
export PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:$PATH
You need only to install libvirt, before the bundle install.
brew install libvirt

Can't install ruby-ldap under Windows/Cygwin

gem install ruby-ldap
Building native extensions. This could take a while...
ERROR: Error installing ruby-ldap:
ERROR: Failed to build gem native extension.
/usr/bin/ruby.exe extconf.rb
--with-ldap-dir=/usr
--with-openldap2
checking for ldap.h... yes
[...]
creating Makefile
make
gcc -I. -I. -I/usr/lib/ruby/1.8/i386-cygwin -I. ...
[...]
gcc -shared -s -o ldap.so ...
The configuration and the compilation works just fine. But the installation throws this error:
make install
/usr/bin/install -c -m 0755 ldap.so /usr/lib/ruby/gems/1.8/gems/ruby-ldap-0.9.12/lib
/usr/bin/install -c -m 644 ./lib/ldap/control.rb /usr/lib/ruby/gems/1.8/gems/ruby-ldap-0.9.12/lib/ldap
/usr/bin/install: `./lib/ldap/control.rb' and `/usr/lib/ruby/gems/1.8/gems/ruby-ldap-0.9.12/lib/ldap/control.rb' are the same file
Makefile:130: recipe for target `/usr/lib/ruby/gems/1.8/gems/ruby-ldap-0.9.12/lib/ldap/control.rb' failed
make: *** [/usr/lib/ruby/gems/1.8/gems/ruby-ldap-0.9.12/lib/ldap/control.rb] Error 1
./lib/ldap/control.rb and /usr/lib/ruby/gems/1.8/gems/ruby-ldap-0.9.12/lib/ldap/control.rb are indeed the same file, but why? Other gems with nativ bindings like mysql worked just fine. I reported this as a bug, but some other guy does not have the problem, so the package itself is intact.
If I download the gem and run:
ruby extconf.rb
make install
The Makefile runs just fine.
It must be my system/configuration. Whats going wrong here?
Wow, very oddly, I got this working by downgrading RubyGems and then upgrading it back. I downgraded it first to match a version (1.4.1) I had on another system that could install ruby-ldap just fine. I thought this might make it work on my current system, but I got the same error you did. I upgraded RubyGems back to what I had (1.8.15), then it all magically worked.
So:
$ gem update --system 1.4.1 # Downgrade to 1.4.1
...
$ gem update --system # Go back to current
...
$ gem install ruby-ldap
Building native extensions. This could take a while...
Successfully installed ruby-ldap-0.9.12
1 gem installed
Installing ri documentation for ruby-ldap-0.9.12...
Installing RDoc documentation for ruby-ldap-0.9.12...
$
FYI, I didn't have to use sudo because I'm using rvm and I was installing ruby-ldap into a per-project gemset.
If you are using Ubunty, try to perform
sudo apt-get install libsasl2-dev
More about it at https://github.com/alexey-chebotar/ruby-ldap/issues/7

Resources