Topic: Can't install sqlite3-ruby gem on Mac OS X

Hello,

I have problems installing the sqlite3-ruby gem on my Mac OS X (10.5) system.

I run the command:

sudo gem install sqlite3-ruby

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

/opt/local/bin/ruby extconf.rb install sqlite3-ruby
checking for fdatasync() in -lrt... no
checking for sqlite3.h... yes
checking for sqlite3_open() in -lsqlite3... yes
creating Makefile

make
gcc -I. -I. -I/opt/local/lib/ruby/1.8/i686-darwin8.10.2 -I. -DHAVE_SQLITE3_H -I/usr/local/include -I/opt/local/include -fno-common -O2  -fno-common -pipe -fno-common  -c sqlite3_api_wrap.c
cc -dynamic -bundle -undefined suppress -flat_namespace -L/opt/local/lib   -L"/opt/local/lib" -L"/usr/local/lib" -o sqlite3_api.bundle sqlite3_api_wrap.o  -lruby -lsqlite3  -lpthread -ldl -lobjc 
ld: in /usr/local/lib/libstdc++.6.dylib, file is not of required architecture
collect2: ld returned 1 exit status
make: *** [sqlite3_api.bundle] Error 1

Gem files will remain installed in /opt/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.4 for inspection.
Results logged to /opt/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.4/ext/sqlite3_api/gem_make.out


How can I get around this?

The sqlite3 version installed is 3.4.0, gem version is 1.3.0, ruby is 1.8.6 (2007-03-13 patchlevel 0) [i686-darwin8.10.2].

Regards,

Tom.

Re: Can't install sqlite3-ruby gem on Mac OS X

Do you have Developer Tools installed?

David Svensson
Rails developer at Standout solutions, Vaxjo, Sweden

Re: Can't install sqlite3-ruby gem on Mac OS X

standout wrote:

Do you have Developer Tools installed?

Mac Developer Tools? Yes.

Re: Can't install sqlite3-ruby gem on Mac OS X

By following these instructions:
http://gist.github.com/15007 (i.e. edit the makefile /opt/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.4/ext/sqlite3_api/Makefile and change LIBPATH from "/usr/local/lib" to "/usr/lib", then running sudo make install)

...I managed to build and install the sqlite3_api.bundle to /opt/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.4/lib

However, rake still complains:

>rake db:schema:load
(in /Users/tom/Documents/Projects/Zyked/Development/svn/ZykedWebRails)
-- create_table("users", {:force=>true})
rake aborted!
no such file to load -- sqlite3

So it seems that Rails cannot find my sqlite3-ruby installation. Any ideas?

Re: Can't install sqlite3-ruby gem on Mac OS X

Do you have multiple versions of ruby installed? It sound like rails is using one of them when you expect it to use the other one. I see that you are using /opt/local....-path. That is not the ruby version that is shipped with Leopard, is it?

David Svensson
Rails developer at Standout solutions, Vaxjo, Sweden

Re: Can't install sqlite3-ruby gem on Mac OS X

I had exactly this problem.

The first thing you need to check is whether that file is there.

in your ruby installation go to (depending on your version): lib/ruby/gems/lib/gems/sqlite-3-ruby-1.2.2/lib/sqlite3

and check if database.rb is there.

If it is open it.

If you get a permission denied try opening it with sudo. If there is nothing there you will need to either get a copy of database.rb or reinstall the gem.

I actually had to download the gem manually because this file was corrupted and reinstall it. I have no idea why.

I also found that it could only be opened with the sudo command which is a problem when you are trying to run anything with rake.

I needed to assign read only permissions to all users (check a mac os forum for assigning permissions).

I have also found this with other gems.

It is probably something more fundemental but I managed to get it working and have had no problems since.

Re: Can't install sqlite3-ruby gem on Mac OS X

Hi standout and StephenI, thanks for your replies!

standout wrote:

Do you have multiple versions of ruby installed? It sound like rails is using one of them when you expect it to use the other one. I see that you are using /opt/local....-path. That is not the ruby version that is shipped with Leopard, is it?

Yes, I have multiple versions. The default one in my path is the same as /opt/local/bin/ruby (ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-darwin8.10.2]).
I think the Leopard version is the one placed in /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby (ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0]).

I think you're on to something. The multiple version thing concerns me. What is the right solution here - should I reconfigure RubyGems to put the gems with the Mac Ruby Framework (/System/Library/Frameworks/...) instead?

StephenI wrote:

in your ruby installation go to (depending on your version): lib/ruby/gems/lib/gems/sqlite-3-ruby-1.2.2/lib/sqlite3
and check if database.rb is there.

I don't think this is the problem I have. My database.rb is there and looks just fine.

Thanks,

Tom.

Re: Can't install sqlite3-ruby gem on Mac OS X

Having two versions of ruby seems like a bad idea. I would completely remove one of them and replace it with symlinks to the version you intend to use.

David Svensson
Rails developer at Standout solutions, Vaxjo, Sweden

Re: Can't install sqlite3-ruby gem on Mac OS X

Tom,

Check the version of your XCode. I had this exact same problem, and was able to install the gem after updating XCode to 3.1 from 2.1

Re: Can't install sqlite3-ruby gem on Mac OS X

Running multiple ruby versions is not a problem - I do this with all kinds of versions. When installing gems, you just have to remember that the gems will be installed local to that ruby version. My day in and day out ruby version is installed in a project dir under my home directory and it works fine. I followed the instructions on the above link (http://gist.github.com/15007) and then had to do some editing of a gemspec file by hand. I'm also running Ruby Enterprise 1.8.6.

Created in my ~/projects/ruby-enterprise-1.8.6/lib/ruby/gems/1.8/specifications dir a file called

sqlite3-ruby-1.2.4.gemspec

here is the source (with the hardcoded version number):

Gem::Specification.new do |s|

   s.name = 'sqlite3-ruby'
   s.version = '1.2.4'
   s.platform = Gem::Platform::RUBY
   s.required_ruby_version = ">=1.8.0"

   s.summary = "SQLite3/Ruby is a module to allow Ruby scripts to interface with a SQLite3 database."

   s.files = Dir.glob("{doc,ext,lib,test}/**/*")
   s.files.concat [ "LICENSE", "README.rdoc", "CHANGELOG.rdoc" ]

   s.require_path = 'lib'

   s.extensions << 'ext/sqlite3_api/extconf.rb'

   s.has_rdoc = true
   s.extra_rdoc_files = [ "README.rdoc" ]
   s.rdoc_options = [ "--main", "README.rdoc" ]

   s.test_suite_file = "test/tests.rb"

   s.author = "Jamis Buck"
   s.email = "jamis@37signals.com"
   s.homepage = "http://sqlite-ruby.rubyforge.org/sqlite3"

end

Then when i type: gem list

the following gem shows up:

sqlite3-ruby (1.2.4)

This is obviously not the best scenario, but it works.

Re: Can't install sqlite3-ruby gem on Mac OS X

What was the ultimate solution to this? I'm facing the same problem on Snow Leopard:

When I do this:


require 'rubygems'
require 'sqlite3'
$db = SQLite3::Database.new("dbfile")

I get this:

/Users/admin/.gem/ruby/1.8/gems/sqlite3-ruby-1.2.5/lib/sqlite3_api.bundle: [BUG] Segmentation fault
ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10]

Abort trap



Things seems fine with SQLite, it's the gem that says it is "successfully installed" yet there's this segmentation fault.

Also the database.rb files looks fine and I can open it in /usr/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.4/lib/sqlite3


Regards,

Karen

Last edited by karenzeller (2010-03-30 23:38:54)

Re: Can't install sqlite3-ruby gem on Mac OS X

karenzeller wrote:

What was the ultimate solution to this? I'm facing the same problem on Snow Leopard

My problems actually went away with a Snow Leopard upgrade.

See if this helps for you: http://blog.docuverse.com/2009/09/24/in … w-leopard/

Tom.

Last edited by tom_soderlund (2010-03-31 04:13:16)

Re: Can't install sqlite3-ruby gem on Mac OS X

Trying to install on OSX 10.6.1.  Just installed gems 1.3.6, rails 2.3.5.  My ruby version is 1.8.7 - shipped with machine.  I get:

Jeff-Whittingtons-MacBook:rails jeff$ sudo gem install sqlite3-ruby
Password:
Building native extensions.  This could take a while...
ERROR:  Error installing sqlite3-ruby:
    ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h


Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/sqlite3-ruby-1.2.5 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/sqlite3-ruby-1.2.5/ext/sqlite3_api/gem_make.out

This could be the same issue the docuverse guy had, but why should I have to install Xcode to fix a ruby error?