關於cannot load such file -- sqlite3/sqlite3_native (LoadError)的錯誤

今天試着用ruby操作sqlite3數據庫,用gem安裝sqlite3數據庫,是沒有問題的。

D:\software\sqlite-amalgamation-3260000\sqlite-amalgamation-3260000>gem install sqlite3
Fetching: sqlite3-1.3.13-x64-mingw32.gem (100%)
Successfully installed sqlite3-1.3.13-x64-mingw32
Parsing documentation for sqlite3-1.3.13-x64-mingw32
Installing ri documentation for sqlite3-1.3.13-x64-mingw32
Done installing documentation for sqlite3 after 1 seconds
1 gem installed

然而在執行程序的時候,卻發生了下面的錯誤。

D:\Ruby25-x64\bin\ruby.exe D:/exercise/Ruby/grep.rb
Traceback (most recent call last):
        7: from D:/exercise/Ruby/grep.rb:1:in `<main>'
        6: from D:/Ruby25-x64/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:39:in `require'
        5: from D:/Ruby25-x64/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
        4: from D:/Ruby25-x64/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:135:in `require'
        3: from D:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sqlite3-1.3.13-x64-mingw32/lib/sqlite3.rb:2:in `<top (required)>'
        2: from D:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sqlite3-1.3.13-x64-mingw32/lib/sqlite3.rb:6:in `rescue in <top (required)>'
        1: from D:/Ruby25-x64/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
D:/Ruby25-x64/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': cannot load such file -- sqlite3/sqlite3_native (LoadError)

Process finished with exit code 1

從網上查找解決辦法,怎麼都解決不了。後來懷疑自己ruby安裝有問題,於是又重新安裝了一下帶dk的ruby。

成功之後,執行gem install sqlite3 --platform=ruby命令,系統仍然報錯,還是找不到sqlite3.h文件。於是從sqlite官網上將代碼和windows用的dll文件分別下載下來,執行以下命令,D:\Ruby25-x64>gem install sqlite3 --platform=ruby -- --with-sqlite3-include=D:/software/sqlite  --with-sqlite3-lib=D:/software/sqlite3

其中:--with-sqlite3-include是頭文件目錄,--with-sqlite3-lib是DLL文件目錄。 終於關聯成功了,

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章