Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing ruby-odbc gem on mac os x 10.9 in RVM

I'm trying to get the ruby-odbc gem installed on a Mac OS X 10.9 under ruby-1.9.3-p547 for use with a rails 2.3.12 application which connects to a SAP system over ODBC.

Environment

  • Mac OS X 10.9 (Mavericks)
  • RVM with ruby 1.9.3 and other rubies installed
  • Gems for Rails 2.3.12 application
  • Brew
  • iODBC installed

Situation

The gem system fails the build when executing

gem install ruby-odbc 

complaining about not being able to find sql.h as in

ERROR: sql.h not found

I then attempted to tell the gem installation environment where the ODBC headers were located via

gem install ruby-odbc -- --with-odbc-dir=/usr/local/iODBC

But this fails still with the following messages (basically still can't find the sql.h header files).

At this point - stuck as unable to get the gem built

This could take a while...
ERROR:  Error installing ruby-odbc:
ERROR: Failed to build gem native extension.

/Users/grantsayer/.rvm/rubies/ruby-1.9.3-p547/bin/ruby extconf.rb --with-odbc-dir=/usr/local/iODBC --with-odbc-include=/usr/local/iODBC/include
checking for version.h... no
checking for sql.h... no
*** 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/grantsayer/.rvm/rubies/ruby-1.9.3-p547/bin/ruby
    --with-odbc-dir
    --with-odbc-include=${odbc-dir}/include
    --with-odbc-lib
    --without-odbc-lib=${odbc-dir}/lib
ERROR: sql.h not found

extconf failed, exit code 1
like image 329
Grant Sayer Avatar asked Sep 26 '14 05:09

Grant Sayer


2 Answers

Have resolved the issue. The key was the command to install the gem as

gem install ruby-odbc -- --with-odbc-dir=/usr/local/iODBC/

The key steps prior to this was to re-install the software stack as per the steps

  1. Install Homebrew: See - Brew via the command

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

  1. Install RVM

$ \curl -sSL https://get.rvm.io | bash -s stable

  1. Install Ruby-1.9.3, which is used by the application which has a connection to ODBC

rvm install ruby-1.9.3

  1. Install the iODBC System See: iODBC Wiki

There are multiple versions, with the Mac OX version provided as a DMG file which provides for the installation of the Driver Manager, within Applications, and the header files necessary for building the ruby-odbc gem

http://www.iodbc.org/dataspace/iodbc/wiki/iODBC/Downloads#Mac%20OS%20X

  1. Install ruby-odbc gem

The ruby-odbc gem is described at Ruby ODBC. This describes the building of the raw source, but the gem install ecosystem will get the sources and build.

gem install ruby-odbc -- --with-odbc-dir=/usr/local/iODBC/

The important part is the path to the installed headers and libraries, which are placed into /usr/local/iODBC via the iODBC install.

Success is when you have the usual happy message that the gem was installed as shown below:

gem install ruby-odbc -- --with-odbc-dir=/usr/local/iODBC/
Building native extensions with: '--with-odbc-dir=/usr/local/iODBC/'
This could take a while...
Successfully installed ruby-odbc-0.99995
Enclosing class/module 'Modbc' for class Object not known
Enclosing class/module 'Modbc' for class Environment not known
Enclosing class/module 'Modbc' for class Database not known
Enclosing class/module 'Modbc' for class Statement not known
Enclosing class/module 'Modbc' for class Column not known
Enclosing class/module 'Modbc' for class Parameter not known
Enclosing class/module 'Modbc' for class DSN not known
Enclosing class/module 'Modbc' for class Driver not known
Enclosing class/module 'Modbc' for class Error not known
Enclosing class/module 'Modbc' for class Date not known
Enclosing class/module 'Modbc' for class Time not known
Enclosing class/module 'Modbc' for class TimeStamp not known
Installing ri documentation for ruby-odbc-0.99995
1 gem installed
like image 135
Grant Sayer Avatar answered Nov 02 '22 22:11

Grant Sayer


I had similar problem on macOs Sierra 10.12

What I did:

brew install libiodbc

Then check version of installed package (should be like libiodbc-3.52.12) if different change in the following command:

gem install ruby-odbc -- --with-odbc-dir=/usr/local/Cellar/libiodbc/3.52.12/

Good luck.

like image 38
LucasM Avatar answered Nov 03 '22 00:11

LucasM