I'm trying to build Ruby 2.2.0 on Ubuntu 14.04.1 and it always fails.
Here are the packages I'm installing beforehand.
DEPENDENCIES = %w{
build-essential bison openssl libreadline6 libreadline6-dev git-core zlib1g
zlib1g-dev libssl-dev libyaml-dev libxml2-dev libgdbm3 libgdbm-dev autoconf
libxslt-dev libc6-dev ncurses-dev automake pkg-config subversion libtool
libffi-dev libncurses5-dev
}
Here's the error I'm getting.
linking shared-object fiddle.so
make[2]: Leaving directory `/usr/local/src/ruby-2.2.0/ext/fiddle'
make[1]: Leaving directory `/usr/local/src/ruby-2.2.0'
STDERR: Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.8.2-19ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.8 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libmudflap --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1)
/usr/bin/ld: ./libffi-3.2.1/.libs/libffi.a(raw_api.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
./libffi-3.2.1/.libs/libffi.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
make[2]: *** [../../.ext/x86_64-linux/fiddle.so] Error 1
make[1]: *** [ext/fiddle/all] Error 2
make: *** [build-ext] Error 2
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.8.2-19ubuntu1' --with- bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.8 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libmudflap --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1)
/usr/bin/ld: ./libffi-3.2.1/.libs/libffi.a(raw_api.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
./libffi-3.2.1/.libs/libffi.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
make[2]: *** [../../.ext/x86_64-linux/fiddle.so] Error 1
make[1]: *** [ext/fiddle/all] Error 2
make: *** [build-ext] Error 2
This issue closely resembled what's described here, but the solution given there is to install a library that I always install first anyway.
libffi-dev is one of the packages I always install first. dpkg -s libffi-dev
shows version Version: 3.1~rc1+r3.0.13-12
installed yet I still get the error I posted in the question.
It looks like this is the solution to the problem.
Can you try the ruby-install
tool?
It does a great job of installing ruby and its dependencies, libraries, etc.
https://github.com/postmodern/ruby-install
Other Ruby installers you may want to consider are rbenv, ruby-build, rvm, and Brightbox.
Even if your goal is to install Ruby from source, you may find it helpful to try a ruby installer, to figure out what steps your install may be missing and how to solve your error.
Can you verify that your libffi-dev is correct?
dpkg -s libffi-dev
I have Ubuntu 14 and Ruby 2.2.0 and my libffi-dev is showing:
Version: 3.1~rc1+r3.0.13-12
Whereas your error message shows your installation is trying to use a newer version:
libffi-3.2.1
Update...
I ran dpkg -s libffi-dev and I got Version: 3.1~rc1+r3.0.13-12.
Good:
Your system has the correct libffi, the same version in the official packages.
Whereas your Ruby installation is attempting to use a different version.
This mismatch shows that your Ruby installation is not finding your system libffi.
When I download Ruby 2.2.0 source, I see that the fiddle
directory has a different libffi
than my system:
➜ ruby-2.2.0 find . | grep libffi
./ext/fiddle/libffi-3.2.1
The libffi directory has it's own README, configure, and Makefile.
If you see the same on your system, you may want to try making it yourself, and possibly installing it too - though I don't know if that would overwrite your system libffi so perhaps proceed cautiously, or install into a custom directory:
./ext/fiddle/libffi-3.2.1
./configure
make
make install
If you get the same essential error and suggestion to compile with -fPIC
then you can try that too. Head up to put -fPIC
as the first arg because some people report that the arg doesn't work later on.
For example to add -fPIC
on your compiler:
CC=gcc -fPIC ...
For example to use -fPIC
on your configure:
CFLAGS=-fPIC ./configure
It seems like you can define a variable named CFLAGS
that will be passed as extra parameters to the compiler(at least that's what I've gathered from it).
So, to be able to properly compile ruby 2.2.0, just run CFLAGS=-fPIC
before your ./configure
call. Example:
CFLAGS=-fPIC
./configure
Obviously if you want to pass any params to configure
, then do so. From there on your make
command should work without any hiccups.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With