ruby-on-rails - 无法在 Mac OS X 10.5.8 (Leopard) 上安装 sqlite3 gem

标签 ruby-on-rails macos sqlite rubygems sqlite3-ruby

使用
Mac OS X 10.5.8(豹)
ruby 1.9.3p0
gem 版本 1.8.14
sqlite3 版本 3.7.9

我还安装了 Xcode 3.1.4(不确定这是否用于安装 gems)。

我拿了 sqlite3 gem

gem fetch sqlite3

然后拆开包装
gem unpack sqlite3-1.3.5.gem

并 cd 进入新目录
cd sqlite3-1.3.5

执行
ruby setup.rb config

然后 cd 到 ext/sqlite3

然后执行 make

这将返回以下错误消息:
usernamemac:sqlite3 username$ make
compiling backup.c
compiling database.c
database.c: In function 'initialize':
database.c:47: error: 'SQLITE_OPEN_READWRITE' undeclared (first use in this function)
database.c:47: error: (Each undeclared identifier is reported only once
database.c:47: error: for each function it appears in.)
database.c:47: error: 'SQLITE_OPEN_CREATE' undeclared (first use in this function)
database.c:79: error: 'SQLITE_OPEN_READONLY' undeclared (first use in this function)
database.c:81: warning: implicit declaration of function 'sqlite3_open_v2'
database.c: In function 'set_sqlite3_func_result':
database.c:285: error: 'sqlite3_int64' undeclared (first use in this function)
database.c:285: error: syntax error before 'long'
make: *** [database.o] Error 1

在 gem 的 README.rdoc 文件中,我读到了“启用选项 SQLITE_ENABLE_COLUMN_METADATA(有关详细信息,请参阅 www.sqlite.org/compile.html)”,但不明白应该做什么。

谁能帮我解决这个问题?

我尝试过其他方法,例如
Error with MySql while doing Bundle Install
I can't install sqlite3 gem但这些对我不起作用。

更新:我在尝试时遇到了类似的问题
rails new app1 -d mysql

create  vendor/plugins/.gitkeep
run  bundle install
/Users/username/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/generators/app_base.rb:232: warning: Insecure world writable dir /usr/local in PATH, mode 040777
/Users/username/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler.rb:209: warning: Insecure world writable dir /usr/local in PATH, mode 040777
Fetching source index for http://rubygems.org/
Installing rake (0.9.2.2) 
...
Installing jquery-rails (1.0.19) 
Installing mysql2 (0.3.11) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /Users/username/.rbenv/versions/1.9.3-p0/bin/ruby extconf.rb 
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... no
*** 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
    ... (list of switches)

Gem files will remain installed in /Users/username/a/app1/vendor/bundle/gems/mysql2-0.3.11 for inspection.
Results logged to /Users/username/a/app1/vendor/bundle/gems/mysql2-0.3.11/ext/mysql2/gem_make.out
An error occured while installing mysql2 (0.3.11), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.11'` succeeds before bundling.

我已经安装了 gem mysql2 (0.3.11)。

更新2:执行时
gem update

更新 sqlite3-ruby gem 时,我得到以下信息:
Updating sqlite3-ruby
Building native extensions.  This could take a while...
/Users/username/.rbenv/versions/1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:48: warning: Insecure world writable dir /usr/local in PATH, mode 040777
ERROR:  Error installing sqlite3-ruby:
    ERROR: Failed to build gem native extension.

        /Users/username/.rbenv/versions/1.9.3-p0/bin/ruby extconf.rb
checking for sqlite3.h... yes
checking for sqlite3_libversion_number() in -lsqlite3... yes
checking for rb_proc_arity()... yes
checking for sqlite3_initialize()... no
checking for sqlite3_backup_init()... no
checking for sqlite3_column_database_name()... no
checking for sqlite3_enable_load_extension()... no
checking for sqlite3_load_extension()... no
creating Makefile

make
compiling backup.c
compiling database.c
database.c: In function 'initialize':
database.c:47: error: 'SQLITE_OPEN_READWRITE' undeclared (first use in this function)
database.c:47: error: (Each undeclared identifier is reported only once
database.c:47: error: for each function it appears in.)
database.c:47: error: 'SQLITE_OPEN_CREATE' undeclared (first use in this function)
database.c:79: error: 'SQLITE_OPEN_READONLY' undeclared (first use in this function)
database.c:81: warning: implicit declaration of function 'sqlite3_open_v2'
database.c: In function 'set_sqlite3_func_result':
database.c:285: error: 'sqlite3_int64' undeclared (first use in this function)
database.c:285: error: syntax error before 'long'
make: *** [database.o] Error 1


Gem files will remain installed in /Users/username/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.5 for inspection.
Results logged to /Users/username/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.5/ext/sqlite3/gem_make.out
Gems updated: activesupport, activemodel, rack, journey, sprockets, actionpack, railties, coffee-rails, jquery-rails, minitest, rubygems-update, sass-rails
Installing ri documentation for activesupport-3.2.0.rc2...

谢谢

最佳答案

如果您运行的是 Mac OS 10.5.X 或更低版本,则无法运行 sqlite3。您至少需要 Snow Leopard 才能编译它。

而是尝试更改您的 Gemfile 以使用 sqlite3-ruby 1.2.5

gem 'sqlite3-ruby', '1.2.5', :require => 'sqlite3'

关于ruby-on-rails - 无法在 Mac OS X 10.5.8 (Leopard) 上安装 sqlite3 gem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8765071/

相关文章:

python - 我是否应该期望 Python sqlite3 用户定义的函数保留在 SQLite 数据库中?

ruby-on-rails - 访问 URL 参数 Project.find(params[ :project_id]) in the application_helper. rb

ruby-on-rails - 在模型实例上强制加载关联

javascript - Turbolinks 5/ capybara /Rails

linux - 使用 NeoBundle 时跨 mac 和 Ubuntu 服务器同步 vim 设置

linux - 如何将 mv 反转为文件 - Unix

jquery - SQLite数据库+Jquery Mobile

ruby-on-rails - Geocoder Gem - 获取 request.location.country 的 "Reserved"(即使在本地!)

macos - 查找(并杀死)端口 23515 Mac osx

ruby-on-rails - rails : Rake Test:functionals cannot access DB (Sqlite3 on winXP)