'gem install ffi' failed on Mac OS X Yosemite 10.10.5 - ruby-on-rails

I'm trying to set up a RoR environment under RVM on Mac OS X Yosemite 10.10.5 on my macbook pro.
The ruby version that I need to install is 1.9.3-p194 because it's required for my software development project.
So far, I have the following software installed on my Macbook:
RVM
ruby 1.9.3-p194
xcode v6.4 and the respective version of command line tools
Mac OS X version: 10.10.5 Yosemite
It seems I'm running into a problem that the ffi gem (an independency of my project) cannot be built successfully.
I get the following error whenever I try to install the gem via the command "gem install ffi -v '1.9.3'"
MacBook-Pro:demo-project apple$ gem install ffi -v '1.9.3'
Building native extensions. This could take a while...
ERROR: Error installing ffi:
ERROR: Failed to build gem native extension.
/Users/apple/.rvm/rubies/ruby-1.9.3-p194/bin/ruby -r ./siteconf20160428-1898-idt325.rb extconf.rb
checking for ffi_call() in -lffi... *** 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.
Provided configuration options:
--with-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/Users/apple/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
--with-ffi_c-dir
--without-ffi_c-dir
--with-ffi_c-include
--without-ffi_c-include=${ffi_c-dir}/include
--with-ffi_c-lib
--without-ffi_c-lib=${ffi_c-dir}/lib
--with-libffi-config
--without-libffi-config
--with-pkg-config
--without-pkg-config
--with-ffilib
--without-ffilib
/Users/apple/.rvm/rubies/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 /Users/apple/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:461:in `try_link0'
from /Users/apple/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:476:in `try_link'
from /Users/apple/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:619:in `try_func'
from /Users/apple/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:845:in `block in have_library'
from /Users/apple/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:790:in `block in checking_for'
from /Users/apple/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:284:in `block (2 levels) in postpone'
from /Users/apple/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:254:in `open'
from /Users/apple/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:284:in `block in postpone'
from /Users/apple/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:254:in `open'
from /Users/apple/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:280:in `postpone'
from /Users/apple/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:789:in `checking_for'
from /Users/apple/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:840:in `have_library'
from extconf.rb:20:in `<main>'
extconf failed, exit code 1
Gem files will remain installed in /Users/apple/.rvm/gems/ruby-1.9.3-p194/gems/ffi-1.9.3 for inspection.
Results logged to /Users/apple/.rvm/gems/ruby-1.9.3-p194/extensions/x86_64-darwin-14/1.9.1/ffi-1.9.3/gem_make.out
I said I have the xcode command line tools installed, but notice from the given error below that it gave me a hint "You have to install development tools first".
Didn't I have it installed already? I was asking myself out of curiousity.
Then I googled and found out the way how to check if I have xcode command line tools installed. Then I launched the terminal and issued that command as illustrated below, and the result did confirm that the piece of software was already installed.
MacBook-Pro:demo-project apple$ xcode-select -p
/Applications/Xcode.app/Contents/Developer
Here is also my gcc version:
MacBook-Pro:demo-project apple$ gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.5.0
Thread model: posix
I have searched all over the web and tried many solutions, but, unfortunately, without success.
Any advice would be very much appreciated to get this to work.
Updated:
My mkmf.log
package configuration for libffi
cflags: -I/usr/local/Cellar/libffi/3.0.13/lib/libffi-3.0.13/include
ldflags: -L/usr/local/Cellar/libffi/3.0.13/lib
libs: -lffi
"/usr/local/bin/gcc-4.9 -o conftest -I/Users/apple/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/x86_64-darwin14.5.0 -I/Users/apple/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/ruby/backward -I/Users/apple/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1 -I. -I/usr/local/opt/libyaml/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -O3 -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -fno-common -pipe -I/usr/local/Cellar/libffi/3.0.13/lib/libffi-3.0.13/include conftest.c -L. -L/Users/apple/.rvm/rubies/ruby-1.9.3-p194/lib -L/usr/local/opt/libyaml/lib -L. -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib -L/usr/local/Cellar/libffi/3.0.13/lib -lffi -lruby.1.9.1 -lpthread -ldl -lobjc "
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main() {return 0;}
/* end */

Related

Problem installing old version of Rails 5.2.2 - Failed to build gem native extension

I need to install older version of rails - 5.2.2 on Windows 10. I'm new to bash, so I went into this task blind, but I managed to install Ruby 2.5.0p0(which I also need). Now I've been stuck for few hours trying to figure out how to install rails.
After running:
$ gem install rails -v 5.2.2
I'm met with following error message:
ERROR: Failed to build gem native extension.
current directory: C:/Ruby25/lib/ruby/gems/2.5.0/gems/racc-1.6.0/ext/racc/cparse
C:/Ruby25/bin/ruby.exe -r ./siteconf20220223-16448-scx6bw.rb extconf.rb
checking for rb_block_call()... *** 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.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=C:/Ruby25/bin/$(RUBY_BASE_NAME)
C:/Ruby25/lib/ruby/2.5.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from C:/Ruby25/lib/ruby/2.5.0/mkmf.rb:541:in `try_link0'
from C:/Ruby25/lib/ruby/2.5.0/mkmf.rb:559:in `try_link'
from C:/Ruby25/lib/ruby/2.5.0/mkmf.rb:770:in `try_func'
from C:/Ruby25/lib/ruby/2.5.0/mkmf.rb:1057:in `block in have_func'
from C:/Ruby25/lib/ruby/2.5.0/mkmf.rb:947:in `block in checking_for'
from C:/Ruby25/lib/ruby/2.5.0/mkmf.rb:350:in `block (2 levels) in postpone'
from C:/Ruby25/lib/ruby/2.5.0/mkmf.rb:320:in `open'
from C:/Ruby25/lib/ruby/2.5.0/mkmf.rb:350:in `block in postpone'
from C:/Ruby25/lib/ruby/2.5.0/mkmf.rb:320:in `open'
from C:/Ruby25/lib/ruby/2.5.0/mkmf.rb:346:in `postpone'
from C:/Ruby25/lib/ruby/2.5.0/mkmf.rb:946:in `checking_for'
from C:/Ruby25/lib/ruby/2.5.0/mkmf.rb:1056:in `have_func'
from extconf.rb:6:in `<main>'
To see why this extension failed to compile, please check the mkmf.log which can be found here:
C:/Ruby25/lib/ruby/gems/2.5.0/extensions/x86-mingw32/2.5.0/racc-1.6.0/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in C:/Ruby25/lib/ruby/gems/2.5.0/gems/racc-1.6.0 for inspection.
Results logged to C:/Ruby25/lib/ruby/gems/2.5.0/extensions/x86-mingw32/2.5.0/racc-1.6.0/gem_make.out
Temporarily enhancing PATH for MSYS/MINGW...
Building native extensions. This could take a while...
The mkmf log:
"i686-w64-mingw32-gcc -o conftest.exe -IC:/Ruby25/include/ruby-2.5.0/i386-mingw32 -IC:/Ruby25/include/ruby-2.5.0/ruby/backward -IC:/Ruby25/include/ruby-2.5.0 -I. -D_FORTIFY_SOURCE=2 -D__USE_MINGW_ANSI_STDIO=1 -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64 -march=i686 -mtune=generic -O2 -pipe conftest.c -L. -LC:/Ruby25/lib -L. -pipe -lmsvcrt-ruby250 -lgmp -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi "
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <winsock2.h>
4: #include <windows.h>
5: int main(int argc, char **argv)
6: {
7: return 0;
8: }
/* end */
I'm using git bash in case that matters.
The problem occurred when ruby was installed using sudo apt install ruby.
Solution: Install ruby via RVM.

Can't install Jekyll on Mint

I installed ruby and ruby gems, updated both of them, tried to install jekyll using the command
sudo gem install jekyll bundler
it gave me this
Building native extensions. This could take a while...
ERROR: Error installing jekyll:
ERROR: Failed to build gem native extension.
current directory: /var/lib/gems/2.3.0/gems/ffi-1.9.14/ext/ffi_c
/usr/bin/ruby2.3 -r ./siteconf20161209-4826-wdshax.rb extconf.rb
checking for ffi.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.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/bin/$(RUBY_BASE_NAME)2.3
--with-ffi_c-dir
--without-ffi_c-dir
--with-ffi_c-include
--without-ffi_c-include=${ffi_c-dir}/include
--with-ffi_c-lib
--without-ffi_c-lib=${ffi_c-dir}/lib
--with-libffi-config
--without-libffi-config
--with-pkg-config
--without-pkg-config
/usr/lib/ruby/2.3.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /usr/lib/ruby/2.3.0/mkmf.rb:587:in `try_cpp'
from /usr/lib/ruby/2.3.0/mkmf.rb:1091:in `block in have_header'
from /usr/lib/ruby/2.3.0/mkmf.rb:942:in `block in checking_for'
from /usr/lib/ruby/2.3.0/mkmf.rb:350:in `block (2 levels) in postpone'
from /usr/lib/ruby/2.3.0/mkmf.rb:320:in `open'
from /usr/lib/ruby/2.3.0/mkmf.rb:350:in `block in postpone'
from /usr/lib/ruby/2.3.0/mkmf.rb:320:in `open'
from /usr/lib/ruby/2.3.0/mkmf.rb:346:in `postpone'
from /usr/lib/ruby/2.3.0/mkmf.rb:941:in `checking_for'
from /usr/lib/ruby/2.3.0/mkmf.rb:1090:in `have_header'
from extconf.rb:16:in `<main>'
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/ffi-1.9.14/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /var/lib/gems/2.3.0/gems/ffi-1.9.14 for inspection.
Results logged to /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/ffi-1.9.14/gem_make.out
Successfully installed bundler-1.13.6
Parsing documentation for bundler-1.13.6
Done installing documentation for bundler after 7 seconds
1 gem installed
Here is what it says in the log file:
package configuration for libffi is not found
"gcc -o conftest -I/usr/include/x86_64-linux-gnu/ruby-2.3.0 -I/usr/include/ruby-2.3.0/ruby/backward -I/usr/include/ruby-2.3.0 -I. -Wdate-time -D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fPIC conftest.c -L. -L/usr/lib/x86_64-linux-gnu -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fstack-protector -rdynamic -Wl,-export-dynamic -lruby-2.3 -lpthread -lgmp -ldl -lcrypt -lm -lc"
In file included from /usr/include/ruby-2.3.0/ruby/ruby.h:36:0,
from /usr/include/ruby-2.3.0/ruby.h:33,
from conftest.c:1:
/usr/include/ruby-2.3.0/ruby/defines.h:26:19: fatal error: stdio.h: No such file or directory
compilation terminated.
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5: return 0;
6: }
/* end */
I'm running Linux Mint, and I can't find anything to help this problem. One gem of jekyll is installed and I'm able to create jekyll projects, but only partially and I can't run it on my local host and edit it.
Any more questions let me know and I'll try my best to help provide the details.
I had the same problem on Linux Mint 18. Installing build-essential solved it:
sudo apt-get install build-essential
I've been there. Some linux need custom treatment till get done to do something.
You can try to
bundle exec jekyll serve --trace
If you pass, you will find url like this: http://127.0.0.1:4000/

Install pg gem on CentOS 6

I'm trying to setup my VPS (CentOS 6.4) with ruby on rails and postgres.
I installed ruby (2.1.0p0), rails (4.1.0), and postgresql (9.3.4) with no problem.
When I try create new rails app (rails new new_app -d postgresql) it stops when installing the pg gem. I've looked into all SO posts about this error and tried pretty much everything I could find. The most suggested was to run "yum install postgresql-devel" and still didn't work.
Below you can find the ssh output and the mkmf.log. Let me know if need more information...
Output
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/home/deploy/.rvm/rubies/ruby-2.1.0/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
checking for libpq-fe.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.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/home/deploy/.rvm/rubies/ruby-2.1.0/bin/ruby
--with-pg
--without-pg
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
/home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:587:in `try_cpp'
from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:1120:in `block in find_header'
from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:918:in `block in checking_for'
from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:351:in `block (2 levels) in postpone'
from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:321:in `open'
from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:351:in `block in postpone'
from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:321:in `open'
from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:347:in `postpone'
from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:917:in `checking_for'
from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:1119:in `find_header'
from extconf.rb:48:in `'
extconf failed, exit code 1
mkmf.log
"gcc -o conftest -I/home/deploy/.rvm/rubies/ruby-2.1.0/include/ruby-2.1.0/x86_64-linux -I/home/deploy/.rvm/rubies/ruby-2.1.0/include/ruby-2.1.0/ruby/backward -I/home/deploy/.rvm/rubies/ruby-2.1.0/include/ruby-2.1.0 -I. -I/usr/include -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -fPIC conftest.c -L. -L/home/deploy/.rvm/rubies/ruby-2.1.0/lib -Wl,-R/home/deploy/.rvm/rubies/ruby-2.1.0/lib -L/usr/lib64 -Wl,-R/usr/lib64 -L. -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,-rpath,'/../lib' -Wl,-R -Wl,'/../lib' -L'/../lib' -lruby -lpthread -lrt -ldl -lcrypt -lm -lc"
gcc: error trying to exec 'as': execvp: Permission denied
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5: return 0;
6: }
/* end */
Before:
For Centos 6: Right install Postgres 9.* with this guide.
After:
yum install postgresql-libs postgresql-devel
Helpful instruction:
How to setup RoR with Postgres
As you are not using the outdated PostgreSQL version that comes with CentOS 6 (PostgreSQL 8.4), you need to install the -devel package matching your version (PostgreSQL 9.X).
The easiest way is to use the official PostgreSQL yum repository.
As the latest version is 9.5 and it is compatible with all 9.X versions I will write the instructions for that one. In the future you can refer to the official instructions for the updated commands.
yum install http://yum.postgresql.org/9.5/redhat/rhel-7-x86_64/pgdg-redhat95-9.5-2.noarch.rpm
yum install postgresql95-devel
Then install the gem with the -with-pg-config option:
gem install pg -- --with-pg-config=/usr/pgsql-9.5/bin/pg_config
This was easier for me:
ln -s /usr/pgsql-9.5/bin/pg_config /usr/local/bin/
Try something like this;
before "bundle:install" do
run "ls -l #{fetch(:latest_release)}/Gemfile"
#run "bundle config --local --gemfile=#{fetch(:latest_release)}/Gemfile build.pg --with-pg-config=/usr/pgsql-9.1/bin/pg_config"
run "cd #{fetch(:latest_release)} && bundle config build.pg --with-pg-config=/usr/pgsql-9.3/bin/pg_config"
end
You could try installing the pg gem with the postres pg_config file path option:
gem install pg -- --with-pg-config=/usr/pgsql-9.2/bin/pg_config
Please update the path according to your system
Regards
I had this problem on my mac and it was a bash / RVM issue. I had to add this to my bash:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm” . Given that it's finding the config file I would look into this.

Instailling Rails 2.0.0 extconf.rb failure on windows 7

I'm trying to install rails 2.0.0 on my computer. I already have already installed ruby on my computer, running the
ruby -v
command returns
ruby 2.0.0p247 (2013-06-27) [x64-mingw32]
Now, I'm trying to install rails 2.0.0 by running
gem install rails
However, I am running into an error:
C:/Ruby200-x64/bin/ruby.exe extconf.rb
*** 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.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=C:/Ruby200-x64/bin/ruby
--with-atomic_reference-dir
--without-atomic_reference-dir
--with-atomic_reference-include
--without-atomic_reference-include=${atomic_reference-dir}/include
--with-atomic_reference-lib
--without-atomic_reference-lib=${atomic_reference-dir}/
C:/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:430:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from C:/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:515:in `try_link0'
from C:/Ruby200-x64/lib/ruby/2.0.0/mkmf.rb:813:in `try_run'
from extconf.rb:24:in `<main>'
4th line up says I need to install development tools, so I downloaded the dev kit from http://rubyinstaller.org/downloads/ for my 64 bit windows, and ran the following commands without issue:
ruby dk.rb init
ruby dk.rb install
However, I still got the same error after running gem rails install... .am I installing the wrong development tools or something? I'm not sure what's going wrong
Additionally I'm using pik to control my ruby version, if that information is relevant.
Note: I checked out another possible solution that said that my userfolder had spaces in it, causing the install to go wonky, but my user account doesn't have spaces in it, so that didn't help.
*edit: the mkmf file with more info:
"x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby200-x64/include/ruby-2.0.0/x64-mingw32 -IC:/Ruby200-x64/include/ruby-2.0.0/ruby/backward -IC:/Ruby200-x64/include/ruby-2.0.0 -I. -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D_FILE_OFFSET_BITS=64 -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -march=native conftest.c -L. -LC:/Ruby200-x64/lib -L. -lx64-msvcrt-ruby200 -lshell32 -lws2_32 -limagehlp -lshlwapi "
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <winsock2.h>
4: #include <windows.h>
5: int main(int argc, char **argv)
6: {
7: return 0;
8: }
/* end */

Ruby on Rails Oracle DB connection

My main database is a local mysql database, however I would like to occasionally connect to an Oracle database directly in my applications code.
The oracle database is hosted on another RHEL server.
I was unsuccessfull tried to install the ruby-OCI8 gem (ERROR: Failed to build gem native extension.)
I am wondering whether the oracle database has to be local in order to use this gem, or if there are any better ways of achieving this.
gem install ruby-oci8
Building native extensions. This could take a while...
ERROR: Error installing ruby-oci8:
ERROR: Failed to build gem native extension.
/usr/bin/ruby extconf.rb
checking for load library path...
LD_LIBRARY_PATH...
checking /opt/instantclient... yes
/opt/instantclient/libclntsh.so.11.1 looks like an instant client.
checking for cc... *** 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.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/bin/ruby
--with-instant-client
--without-instant-client
./oraconf.rb:562:in `check_cc': RuntimeError (RuntimeError)
from ./oraconf.rb:549:in `init'
from ./oraconf.rb:1001:in `initialize'
from ./oraconf.rb:343:in `new'
from ./oraconf.rb:343:in `get'
from extconf.rb:18
ng
---------------------------------------------------
Error Message:
C compiler doesn't work correctly.
Backtrace:
./oraconf.rb:562:in `check_cc'
./oraconf.rb:549:in `init'
./oraconf.rb:1001:in `initialize'
./oraconf.rb:343:in `new'
./oraconf.rb:343:in `get'
extconf.rb:18
---------------------------------------------------
See:
* http://ruby-oci8.rubyforge.org/en/HowToInstall.html
* http://ruby-oci8.rubyforge.org/en/ReportInstallProblem.html
I checked the mkmf.log file:
"gcc -o conftest -I. -I/usr/lib64/ruby/1.8/x86_64-linux -I. -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fs tack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fno-strict-aliasing -fPIC conftest.c -L. -L/usr/lib64 -L. -rdynamic -Wl,-export-dynamic -lruby-static -lpthread -lrt -ldl -lcrypt -lm -lc"
/usr/bin/ld: skipping incompatible /usr/lib/libruby-static.a when searching for -lruby-static
/usr/bin/ld: cannot find -lruby-static
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: int main() { return 0; }
8 /* end */
At first you need to install Oracle Instant Client - choose corresponding Linux 32-bit or 64-bit binaries. To be safe use older version 10.2.0.4 which I use in all my Ruby and Oracle projects. Install Basic, SDK and SQL*Plus packages.
Then include Oracle Instant Client installation directory in LD_LIBRARY_PATH environment variable so that Oracle Instant Client dynamic libraries would be in load path.
Then try to install ruby-oci8 gem.
Afterwards install activerecord-oracle_enhanced-adapter gem to be able to access Oracle database from ActiveRecord.
I have posted instructions how to install ruby-oci8 on Mac OS X - majority of this applies to Linux as well (DYLD_LIBRARY_PATH on Mac corresponds to LD_LIBRARY_PATH on Linux).
In addition I have created Sprinkle recipe for automated Oracle client installation on Linux - probably it is not the best way to start with this but in case you want to build automated server installation scripts then you can take a look on it.
See if this blog post helps you in getting through the OCI gem install http://jessehu.wordpress.com/2008/07/03/ruby-oci8-gem-available-2/
You can install the ruby-oci8 gem like below,
LD_LIBRARY_PATH=/local/home/soundar/instantclient_11_2 gem install ruby-oci8
Note: LD_LIBRARY_PATH is a enviroment variable set by oracle instant client directory path

Resources