Rails, pow and Library not loaded: /usr/local/lib/libsqlite3.0.8.6.dylib
Asked Answered
A

1

8

I didn't work on this rails app for a couple of weeks. Yesterday I got back to it, first opening the .dev URL (i'm using pow) and it gave this error message:

LoadError: dlopen([...]/vendor/bundle/gems/sqlite3-1.3.7/lib/sqlite3/sqlite3_native.bundle, 9): Library not loaded: /usr/local/lib/libsqlite3.0.8.6.dylib Referenced from: [...]/vendor/bundle/gems/sqlite3-1.3.7/lib/sqlite3/sqlite3_native.bundle Reason: image not found - [...]/vendor/bundle/gems/sqlite3-1.3.7/lib/sqlite3/sqlite3_native.bundle

I checked the rbenv install and all seemed fine. I tried to think of recent changes that could lead to this but I can't. I'm pretty sure I'm missing something but my attempts to debug it were futile. I don't know if it's relevant but I recently switched to zsh.

Acnode answered 31/3, 2013 at 14:43 Comment(0)
V
24

Solution

Uninstall and reinstall sqlite:

~/d/w/r/my-app git:master ❯❯❯ gem uninstall sqlite3                                                                      

Successfully uninstalled sqlite3-1.3.7

~/d/w/r/my-app git:master ❯❯❯ gem install sqlite3                                                                            
Fetching: sqlite3-1.3.7.gem (100%)
Building native extensions.  This could take a while...
Successfully installed sqlite3-1.3.7
1 gem installed

What Happened

When the sqlite3 gem is installed, it builds a native component for talking to sqlite and so it links against the local sqlite3 libraries. This is all handled behind the scenes by gem. When that happens, it specifies the location of the library that it linked against.

Recently (January), the homebrew formula for sqlite became keg-only. Anything that was previously linked against sqlite referenced the homebrew version. You can check this by using otool -L:

~/d/w/r/my-app git:master ❯❯❯ otool -L /path/to/earlier/gem/sqlite3-1.3.6/lib/sqlite3/sqlite3_native.bundle
/path/to/earlier/gem/sqlite3-1.3.6/lib/sqlite3/sqlite3_native.bundle:
    /usr/local/lib/libsqlite3.0.8.6.dylib (compatibility version 9.0.0, current version 9.6.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
    /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)

Running otool against the new version you can see that it is now linked against the Apple-provided system sqlite libraries:

~/d/w/r/a/new-config git:master ❯❯❯ otool -L /path/to/new/gem/sqlite3-1.3.7/lib/sqlite3/sqlite3_native.bundle
 /path/to/new/gem/sqlite3-1.3.7/lib/sqlite3/sqlite3_native.bundle:
    /usr/lib/libsqlite3.dylib (compatibility version 9.0.0, current version 9.6.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
    /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
Virtuosic answered 15/4, 2013 at 16:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.