Windows 10上安装Ruby sqlite3 gem出现问题

3

我对Ruby和Rails非常陌生。我正在尝试安装sqlite3以便进行教程尝试,但是出现了一些问题。我使用的操作系统是Windows 10,并且使用的是ruby 2.6.1p33 (2019-01-30 revision 66950) [x64-mingw32]

以下是我在运行gem install sqlite3-ruby时遇到的安装错误。我也尝试运行了gem install sqlite3 --platform=ruby -- --with-sqlite3-include=c:/sqlite3/include --with-sqlite3-lib=c:/sqlite3/lib

C:/Ruby26-x64/bin/ruby.exe -I C:/Ruby26-x64/lib/ruby/2.6.0 -r ./siteconf20190217-3116-1d59gcv.rb extconf.rb
checking for sqlite3.h... yes
checking for pthread_create() in -lpthread... yes
checking for -ldl... no
checking for dlopen()... no
missing function dlopen
*** 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.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=C:/Ruby26-x64/bin/$(RUBY_BASE_NAME)
    --with-sqlcipher
    --without-sqlcipher
    --with-sqlite3-config
    --without-sqlite3-config
    --with-pkg-config
    --without-pkg-config
    --with-sqlcipher
    --without-sqlcipher
    --with-sqlite3-dir
    --without-sqlite3-dir
    --with-sqlite3-include
    --without-sqlite3-include=${sqlite3-dir}/include
    --with-sqlite3-lib
    --without-sqlite3-lib=${sqlite3-dir}/lib
    --with-pthreadlib
    --without-pthreadlib
    --with-dllib
    --without-dllib

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  C:/Ruby26-x64/lib/ruby/gems/2.6.0/extensions/x64-mingw32/2.6.0/sqlite3-1.4.0/mkmf.log

extconf failed, exit code 1

我已经从sqlite3官网下载了文件,以下是C:\sqlite3\的文件夹结构:

sqldiff.exe
sqlite3.exe
sqlite3_analyzer.exe
include\shell.c
include\sqlite3.c
include\sqlite3.h
include\sqlite3ext.h
lib\sqlite3.def
lib\sqlite3.dll

我也已经将 sqldiff.exe, sqlite3.exe 和 sqlite3_analyzer.exe 复制到了 C:\Ruby26-x64\bin 中。 在我的环境变量中,我已经添加了 C:\sqlite3\PATH 中,并创建了一个新的环境变量 sqlite3-dir,指向 C:\sqlite3\
请问是否有人能提供一些关于这个安装问题的帮助?

您需要最新版本吗?我也遇到了sqlite3 1.4.0的问题,但是1.3.13版本对我来说很好用。请尝试使用gem install sqlite3 -v 1.3.13安装。 - knut
1
我能够通过这个链接中的步骤解决了这个问题:https://github.com/sparklemotion/sqlite3-ruby/issues/241 - Samiul Alam Anik
1
正好碰上这个问题。我正在学习Ruby on Rails,刚在我的第一个项目中遇到了这个错误。 - Peet Brits
有人在评论中放了那个链接。不知道为什么那条评论被删除了。 - Samiul Alam Anik
4个回答

3
在项目的Gemfile文件中添加gem 'sqlite3', git: "https://github.com/larskanis/sqlite3-ruby", branch: "add-gemspec"可以生效。之后运行bundle install。确保在机器上安装了git。这是github链接

2

这是目前对我有效的解决方案,它是一个项目级别的修复;参考 Samiul Alam Anik 的答案,但有所补充。在你遵循那些步骤之后,你可能会遇到 需要 Bundler 2 的问题,这个问题可以通过使用 gem update --system 来解决,感谢这个 GitHub ticket


1
为了解决所有项目的这个问题,我从 https://rubygems.org/ 下载了 gem 文件并将其保存在本地,通过 cmd 安装了 MinGW。
C:\Sites>ridk exec pacman -S mingw-w64-x86_64-dlfcn

SQLite 3 gem之后

C:\Sites>gem install --local C:\sqlite3-1.4.0.gem

如果您需要修复已创建的项目,请尝试在这些行之后再次运行bundle install,它将适用于Sites文件夹中创建的所有下一个项目。

我还尝试将SQLite 3文件包含到路径中,但对我也没有起作用。


-1

请确保您的计算机上安装了当前版本的Ruby,安装node ja,安装yarn,更新npm,更新gem Ruby。

C:\Users\adilkemo>ruby --version 
ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x64-mingw32]

C:\Users\adilkemo>gem --version  
3.2.15

C:\Users\adilkemo>node --version  
v16.4.2

C:\Users\adilkemo>yarn --version  
1.22.10

C:\Users\adilkemo>npm --version   
7.18.1

C:\Users\adilkemo>sqlite3 --version  
3.36.0 2021-06-18 18:36:39 5c9a6c06871cb9fe42814af9c039eb6da5427a6ec28f187af7ebfb62eafa66e5

C:\Users\adilkemo>gem install rails 

C:\Users\adilkemo>rails --version  
Rails 6.1.4

C:\Users\adilkemo>cd Desktop  

C:\Users\adilkemo\Desktop>rails new blog  

C:\Users\adilkemo\Desktop>cd blog  

C:\Users\adilkemo\Desktop\blog>bin/rails server - Goodbye!
Exiting
Terminate batch job (Y/N)? y  

C:\Users\adilkemo\Desktop\blog>

https://rubyinstaller.org/
https://guides.rubygems.org/rubygems-basics/
https://nodejs.org/en/
https://classic.yarnpkg.com/en/docs/install/#windows-stable
https://www.sqlite.org/download.html
https://guides.rubyonrails.org/v5.0/getting_started.html


请阅读 https://stackoverflow.com/editing-help。请理解编辑提示字段的目的。请仔细检查我的修改是否对您的帖子产生了影响,我的意图只是为了让您的信息呈现出正确的形式,而不是参与这个社区维基帖子(因为我很惊讶您选择了创建这个帖子)。 - Yunnosch

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接