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

2

9

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
Baskin answered 26/9, 2014 at 5:56 Comment(1)
One additional item - notice that I can build the odbc.bundle if i do it outside of gem; i.e using the downloaded source package and running ruby -Cext extconf.rbBaskin
B
9

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
Baskin answered 29/9, 2014 at 4:13 Comment(2)
You can also install the iODBC with brew install libiodbc and then install the gem with gem install ruby-odbc -- --with-odbc-dir=/usr/local/Cellar/libiodbc/3.52.12/bin/iodbc Make Sure To Match The Version In The PathPylos
I just installed mine a few minutes ago. But in my bin folder I have these 3 files: iodbc-config iodbctest iodbctestw I'm not seeing how I should proceed to have iodbc.ini file.Obscurity
C
6

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.

Chouinard answered 4/10, 2016 at 13:30 Comment(1)
you can use "$(brew --prefix libiodbc)" to automatically get the path to the installed version of odbc. full command will then be gem install ruby-odbc --with-odbc-dir="$(brew --prefix libiodbc)"Reforest

© 2022 - 2024 — McMap. All rights reserved.