views:

1855

answers:

5

So, I can't for the life of my get this working properly. My ultimate goal is to get the dbd-odbc gem installed and working, and from multiple things I've read, I need to install the ODBC binding for ruby alongside the dbd-odbc gem. Well, I can get the dbd-odbc gem installed just fine, but when it comes to trying to install the binding it tanks out on me like so:

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

c:/tools/ruby/ruby-1.9.1-p376/bin/ruby.exe extconf.rb
checking for version.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
        --srcdir=.
        --curdir
        --ruby=c:/tools/ruby/ruby-1.9.1-p376/bin/ruby
        --with-odbc-dir
        --without-odbc-dir
        --with-odbc-include
        --without-odbc-include=${odbc-dir}/include
        --with-odbc-lib
        --without-odbc-lib=${odbc-dir}/lib
c:/tools/ruby/ruby-1.9.1-p376/lib/ruby/1.9.1/mkmf.rb:364:in 'try_do': The complier failed to generate an executable file. (RuntimeError)  
You have to install development tools first.  
        from c:/tools/ruby/ruby-1.9.1-p376/lib/ruby/1.9.1/mkmf.rb:433:in 'try_cpp'
        from c:/tools/ruby/ruby-1.9.1-p376/lib/ruby/1.9.1/mkmf.rb:811:in 'block in have_header'
        from c:/tools/ruby/ruby-1.9.1-p376/lib/ruby/1.9.1/mkmf.rb:670:in 'block in checking_for'
        from c:/tools/ruby/ruby-1.9.1-p376/lib/ruby/1.9.1/mkmf.rb:276:in 'block (2 levels) in postpone'
        from c:/tools/ruby/ruby-1.9.1-p376/lib/ruby/1.9.1/mkmf.rb:250:in 'open'
        from c:/tools/ruby/ruby-1.9.1-p376/lib/ruby/1.9.1/mkmf.rb:276:in 'block in postpone'
        from c:/tools/ruby/ruby-1.9.1-p376/lib/ruby/1.9.1/mkmf.rb:250:in 'open'
        from c:/tools/ruby/ruby-1.9.1-p376/lib/ruby/1.9.1/mkmf.rb:272:in 'postpone'
        from c:/tools/ruby/ruby-1.9.1-p376/lib/ruby/1.9.1/mkmf.rb:669:in 'checking_for'
        from c:/tools/ruby/ruby-1.9.1-p376/lib/ruby/1.9.1/mkmf.rb:810:in 'have_header'
        from extconf.rb:22:in ''

So...reading through it, it says I have to install the development tools first. Fine and dandy. I go here, and grab the dev kit. I wander here, and read through the instructions on how to install it. I install it.
On a side note - I've tried this with a one-click install of 1.9.1 from the ruby installer site. I've tried this with precompiled mswin-32 binaries of ruby, under 1.8.6, 1.8.7 and 1.9.1. None of them have worked.
I'll stick with the one-click installer since that's what all the instructions I've come across the web seem to be using. Fine. It says to edit my fstab file. I do. Here's my current setup:
My ruby installation is sitting in: C:\tools\ruby\ruby19 The devkit has been extracted into this directory, and I can check the /bin and see gcc.bat, make.bat and sh.bat in there.
I follow the directions and modify my devkit/msys/1.0.11/etc/fstab file. It now looks like this:
C:/tools/ruby/ruby19/devkit/gcc/3.4.5 /mingw C:/tools/ruby/ruby19/devkit/msys/1.0.11/usr/local /usr/local

No matter what I seem to do, I cannot for the life of me get the odbc binding gem to compile to native extensions. I keep getting the same error over and over. This is getting highly frustrating - please help!

+1  A: 

You're killing yourself.

For Win32 operating systems DLLs of 0.997 are available in i386-msvcrt-ruby-odbc.zip. It contains the files odbc.so and odbc_utf8.so which need to be copied into the .../ruby/1.8/i386-msvcrt directory of MSVC based Ruby 1.8 installations.

Try putting those files where recommended, then installing that version of the gem, and see how it goes.

Trevoke
You know, I tried this over and over but I failed to read the key part of that statement... of MSVC based Ruby 1.8 installations.So back to 1.8.7 one click installer, copying those .so files over where needed and it seems to be working. I guess it's just not ready for 1.9 yet.
bergyman
A: 

Okay, please clarify:

I did a fresh install of rubyforge.org/frs/download.php/69034/rubyinstaller-1.8.7-p249-rc2.exe and the devkit (rubyforge.org/frs/download.php/66888/devkit-3.4.5r3-20091110.7z) There was no "../ruby/1.8/i386-msvcrt" directory, so I made one. I downloaded http://www.ch-werner.de/rubyodbc/i386-msvcrt-ruby-odbc.zip and put the two files in that directory.

Then I downloaded www.ch-werner.de/rubyodbc/ruby-odbc-0.997.tar.gz, decompressed it, and followed the instructions in the readme. "ruby extconf.rb>>make>>make install" which says, "/bin/install -c -m 0755 odbc.so c:/Ruby/lib/ruby/site_ruby/1.8/i386-msvcrt" So, now there's a /i386-msvcrt under ../ruby/site_ruby/1.8, and one under ..ruby/1.8. I suppose that's right, but it still doesn't connect to SQL Server the way it did last week before my HD crashed and I had to reinstall everything.

Very frustrating, especially since I'm probably doing something that "everyone" knows is not intended. Or, maybe I didn't read carefully enough. Whatever. At this point, I'll slavishly follow the OP's route. I am just stuck.

Ron Phillips
A: 

Ok, I think this is the minimum. I uninstalled everything: c:\ruby, MinGW, MSYS, all the stuff I fiddled trying to get this to run.

Then I:

  1. installed Ruby One-Click: http://rubyforge.org/frs/download.php/69034/rubyinstaller-1.8.7-p249-rc2.exe
  2. "gem install activerecord-sqlserver-adapter"
  3. "gem install rails"
  4. installed devkit: unzipped rubyforge.org/frs/download.php/66888/devkit-3.4.5r3-20091110.7z into c:\ruby
  5. "gem install ruby-odbc", which built and installed v. 0.999
  6. made a DSN called dev-travel-dsn using "Control Panel>Administrative Tools>Data Sources(ODBC)"
  7. put this in my database.yml:

development:
    adapter: sqlserver
    mode: odbc
    dsn: dev_travel_dsn
    username: some_user
    password: some_secret
    host: some_host

I ran "rake db:schema:dump," which worked just fine.

It's odd, but even if you put a lot of the same things in the DSN Manager, you have to put them in database.yml, too.

Anyway, those seem to be the minimum requirements to use Sql Server/Rails 2.3.5/Windows.

A: 

man, i've been trying this for days! The sequence matters or what i don't know but it's finally working

SiS
A: 

This worked for me with rails 3 as well. I ran into 2 gotchas in the process. 1. Ruby 1.9.2 wouldn't let me install ruby-odbc so I switched back to 1.8.7. and 2. For Rails 3 you have to include the following lines in your gemfile:

gem 'activerecord-sqlserver-adapter'

gem 'ruby-odbc'

After that, the above instructions worked flawlessly!

Cliff