8

我已经有几个星期没有在这个 Rails 应用程序上工作了。昨天我回到它,首先打开 .dev URL(我正在使用 pow),它给出了这个错误消息:

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

我检查了 rbenv 安装,一切似乎都很好。我试图考虑可能导致这种情况的最近变化,但我做不到。我很确定我错过了一些东西,但我尝试调试它是徒劳的。我不知道它是否相关,但我最近切换到 zsh。

4

1 回答 1

24

解决方案

卸载并重新安装 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

发生了什么

安装 sqlite3 gem 后,它会构建一个与sqlite对话的本机组件,因此它会链接到本地​​ sqlite3库。这一切都由gem在幕后处理。发生这种情况时,它会指定它链接的库的位置。

最近(1 月),sqlite自制公式变成了 keg-only。之前与sqlite链接的任何内容都引用了自制版本。您可以使用以下方法检查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)

针对新版本运行otool,您可以看到它现在与 Apple 提供的系统 sqlite 库链接:

~/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)
于 2013-04-15T16:24:36.127 回答