views:

2734

answers:

5

Hi all, I got ruby 1.8.7 (native compiled), rails 2.3.4, OSX 10.6.2 and also sqlite3-ruby.

The error I'm getting when accessing the rails app is

NameError: uninitialized constant SQLite3::Driver::Native::Driver::API

History:
I upgraded to snow leopard by migrating my apps with a FW-cable from my old macbook to the new one. Everything was running perfectly for months, but Yesterday I needed to install watir, which was dependant on rb-appscript, which didn't build due a "wrong architecture" error in libsqlite3.dylib. I figured the build was made on the old machine, so i wanted to rebuild sqlite3-ruby:

$ sudo gem uninstall sqlite3-ruby

$ sudo gem install sqlite3-ruby

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

/usr/local/bin/ruby extconf.rb
checking for fdatasync() in -lrt... no
checking for sqlite3.h... yes
checking for sqlite3_open() in -lsqlite3... 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.

It seems like the sqlite3 libs are not working properly. I've tried to install macports sqlite3 (sudo port install sqlite3) and use that instead, but with same result... so i rebuild sqlite3 from scratch.. download->configure->make->make install. After that, the gem now builds perfectly, but doesn't work in rails, giving the error in the top of this article.

I'm not really sure where to go from here because I've tried the following

  1. Rebuild sqlite3 from newest source (http://www.sqlite.org/download.html)
  2. Reinstalled sqlite3-ruby (sudo gem uninstall sqlite3-ruby && sudo gem install sqlite3-ruby)
  3. Used sqlite3 from macports (sudo port install sqlite3 && sudo gem install sqlite3-ruby)
  4. Reinstalled rails (sudo gem install rails sqlite3-ruby ) and updated environment.rb to rails 2.3.5.

No avail, I still get this error:

NameError: uninitialized constant SQLite3::Driver::Native::Driver::AP
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:105:in const_missing'
from /usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.5/lib/sqlite3/driver/native/driver.rb:76:in
open'
from /usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.5/lib/sqlite3/database.rb:76:in `initialize'

Btw, I have Xcode installed from the Snow Leopard CD.

What can i do to solve the problem?

A: 

I found some guidance on this at Don Park's blog at:

http://blog.docuverse.com/2009/09/24/installing-sqlite3-ruby-gem-on-snow-leopard/

His solution points right back to Stack Overflow at the following thread:

http://stackoverflow.com/questions/1373108/snow-leopard-sqlite3-ruby

The answer about the ln command seems to have solved my problem. Hope it helps you too.

Mike Richardson
A: 

If the gem isn't building it's not because you need necessarily to rebuild sqlite3 from source, but to build the gem you will require the sqlite3 developer libraries.

On most Linux/Unix systems you can install them by doing 'sudo apt-get install sqlite3-dev', however I'm not sure how it works with Macports - but make sure you have that package. You have to make sure they're in your path or pass the dir they're in when you install the gem (see the gem's output for hints as to the options for doing that).

I have sqlite3 running on my Mac just fine, both with 1.8.7 and now my updated 1.9.1 Ruby. You might want to make sure you have the XCode Developer Tools installed as well.

Nicholas C
A: 

Thanks for the answers. Here is what i did to solve the problem:

  1. Complete reinstall of ruby1.8.7 to /usr/local, see here: http://hivelogic.com/articles/ruby-rails-leopard

    Note: readline wasn't working when recompiling ruby on my mac, so i had to build that too from scratch and make sure to add the --with-readline-dir option to configure:

    ./configure --enable-shared --enable-pthread CFLAGS=-D_XOPEN_SOURCE=1 --prefix=/usr/local --with-readline-dir=/usr/local

  2. Complete reinstall of sqlite3 to /usr/local

  3. Rebuild all gems on the system with sudo gem install XXX, including sqlite3-ruby. This is only necessary with platform specific gems, but i found it to be faster just to install everything in a oneliner:

    sudo gem install gem1 gem2 ... gemN --no-ri --no-rdoc

I tried to go with ruby1.9 but everything stopped working due to broken dependencies in gems and plugins, so I wouldn't recommend switching to 1.9 unless you are up for some heavy debugging and know how to restore your old system!

Finally everything is running again!

Carl Tessler
how do you install sqlite3 to a specific directory?
CodingWithoutComments
A: 

For those on Snow Leopard 64 and having this issue installing this macport fixed the issue for me.

sudo port install rb-sqlite3 +universal

nacengineer
A: 

My problem was slightly different, and in fact non of the solutions I found on-line worked.

When trying to install sqlite3-ruby after upgrading to Snow Leopard and XCode 4.0 trial, I got the message

checking for sqlite3.h... yes
checking for sqlite3_libversion_number() in -lsqlite3... no
sqlite3 is missing. Try 'port install sqlite3 +universal' or 'yum install sqlite3-devel'

however sqlite3 was installed, and also re-installing did not help. I already had the troub le before with 64-bit and universal versions, but that I had cleared as well. In fact, I could work with sqlite3.

So gem install should also tell you something along these lines:

Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/sqlite3-ruby-1.3.1 for inspection.

So cd to that directory and there look for extconf.rb, mine was in ./ext/sqlite3/extconf.rb I found that ruby was checking for the the sqlite3 library using

asplode('sqlite3') unless find_library 'sqlite3', 'sqlite3_libversion_number'

So I fired up irb and checked why this didn't work:

  require 'mkmf'
   find_library 'sqlite3', 'sqlite3_libversion_number'

Well, in fact this works and my ruby find the library. So why doesn't it work from the setup? Inspecting extconf.rb closely showed the following line:

  sqlite = dir_config('sqlite3', ['/usr/local', '/opt/local', '/usr'])

When I execute this in irb:

require 'mkmf'
  sqlite = dir_config('sqlite3', ['/usr/local', '/opt/local', '/usr']) 
  find_library 'sqlite3', 'sqlite3_libversion_number'

I will surprisingly not find the library anymore. In fact I do not understand how this can be, but that's what happens.

So this is the cure: comment out the line

sqlite = dir_config('sqlite3', ['/usr/local', '/opt/local', '/usr'])

in extconf.rb

Then from /Library/Ruby/Gems/1.8/gems/sqlite3-ruby-1.3.1 I issued

 sudo ruby ./setup.rb

This went through with no problems (I tried before commenting out the sqlite= line, and it did not work)

Restarted the ruby application that had the problems with sqlite. Works fine.

Hope this will help someone.

Icecream

Icecream