通过bundler安装sqlite3 gem出错

15
我正在尝试在我的账户上安装sqlite3-ruby gem(版本1.3.4),但由于我在共享托管的CentOS上操作,所以需要在没有root权限的情况下进行安装。并且已安装的sqlite版本不足够新以支持更高版本的sqlite3-ruby,因此需要在我的账户下编译库文件。我使用的sqlite版本是1.7.0,因为我发现较新版本存在问题。
我已经完成了这个步骤 - 我下载了sqlite-3.7.0.tar.gz,并按照以下方式安装:
./configure –prefix=$HOME
make && make install

接下来我去我的Rails 3应用程序并运行了以下命令:

bundle config build.sqlite3-ruby “--with-sqlite3-include=$HOME/include --with-sqlite3-lib=$HOME/lib”

那么:

bundle install --path vendor/bundle

然而,我会收到以下错误信息,导致我的捆绑包无法完全安装:

Installing sqlite3 (1.3.4) with native extensions /usr/lib/ruby/site_ruby/1.8/rubygems/installer.rb:533:in `build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

        /usr/bin/ruby extconf.rb
checking for sqlite3.h... yes
checking for sqlite3_libversion_number() in -lsqlite3... yes
checking for rb_proc_arity()... no
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
gcc -I. -I. -I/usr/lib/ruby/1.8/x86_64-linux -I.  -fPIC -g -O2  -fPIC   -c sqlite3.c
gcc -I. -I. -I/usr/lib/ruby/1.8/x86_64-linux -I.  -fPIC -g -O2  -fPIC   -c exception.c
gcc -I. -I. -I/usr/lib/ruby/1.8/x86_64-linux -I.  -fPIC -g -O2  -fPIC   -c backup.c
gcc -I. -I. -I/usr/lib/ruby/1.8/x86_64-linux -I.  -fPIC -g -O2  -fPIC   -c 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:72: error: 'SQLITE_OPEN_READONLY' undeclared (first use in this function)
database.c: In function 'set_sqlite3_func_result':
database.c:278: error: 'sqlite3_int64' undeclared (first use in this function)
make: *** [database.o] Error 1
任何想法?这个之前可以用,但是使用最新版本的sqlite3-ruby好像不行了。
以下是一些额外信息:
rails -v
Rails 3.0.9

gem -v
1.7.2

.bash_profile:

PATH=$HOME/bin:$PATH
GEM_HOME=$HOME/gems
GEM_PATH=$HOME/gems
export LD_LIBRARY_PATH=$HOME/lib
export USERNAME BASH_ENV PATH GEM_HOME GEM_PATH

which sqlite3
/home/striketh/bin/sqlite3

编辑:

我已经改变了我的Gemfile中的sqlite3-ruby为sqlite3并运行了以下命令:

bundle config build.sqlite3 “--with-sqlite3-include=$HOME/include --with-sqlite3-lib=$HOME/lib --with-sqlite3-dir=$HOME”

这个错误信息让我很疑惑:

make
gcc -I. -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -DHAVE_SQLITE3_INITIALIZE -DHAVE_SQLITE3_BACKUP_INIT -I/home/striketh”/include    -fPIC -g -O2  -fPIC   -c sqlite3.c
In file included from ./sqlite3_ruby.h:42,
                 from sqlite3.c:1:
./backup.h:7: error: expected specifier-qualifier-list before 'sqlite3_backup'
make: *** [sqlite3.o] Error 1

还有其他的想法吗?


使用Homebrew或MacPorts重新构建SQLite3。 - thenengah
@Codeglot 在 CentOS 上?祝你好运 :). - Lukas Stejskal
除了sqlite3之外,您还需要安装一些sqlite3开发库,不幸的是我不知道具体是哪些。在Debian上,它是libsqlite3-dev和libsqlite3-0。 - Lukas Stejskal
该软件包已经安装在系统上,但由于操作系统级别的sqlite版本过时,我无法依赖它。我可以使用gem install sqlite3来解决 - 我需要找出是否有一个参数可以传递给bundler来修改gcc查找所有内容的位置,因为这是阻止我通过bundler安装的唯一原因。 - Striketh
5个回答

13

这是已经验证可行的解决方案。

.bash_profile设置:

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$HOME/bin:$PATH
GEM_HOME=$HOME/gems
GEM_PATH=$HOME/gems
export LD_LIBRARY_PATH=$HOME/lib
export USERNAME BASH_ENV PATH GEM_HOME GEM_PATH

然后运行:

wget http://www.sqlite.org/sqlite-autoconf-3070701.tar.gz
tar -zxvf sqlite-autoconf-3070701.tar.gz
cd sqlite-autoconf-3070701
./configure --prefix=$HOME
make && make install

cd $RAILS_APP_DIR
vi Gemfile

请确保Gemfile文件中有类似以下的一行代码:gem 'sqlite3', "1.3.4"

bundle config build.sqlite3 --with-sqlite3-include=$HOME/include --with-sqlite3-lib=$HOME/lib --with-sqlite3-dir=$HOME/bin
bundle install --path vendor/bundle

我在我的CentOS主机上使用sqlite 3.3.6,rails 3.0.9和gem 1.5.2遇到了相同的编译错误。我有系统的root访问权限,并且我的gems位于/opt中,所以我不确定如何应用您的修复方法。您能给我一些提示,帮助我编译吗?我需要安装sqlite-autoconf吗?我只是使用我的存储库之一中的软件包。 - Arosboro
4
仅供以后参考,宝石库sqlite3需要sqlite 3.6.16或更高版本。CentOS自带的是v3.3.6,无法与此宝石库配合使用。 - Augusto
1
感谢您提供的 SQLite 版本要求提示。在 CentOS 上,通过源代码编译并使用 gem install sqlite3 -- --with-sqlite-dir=/usr/local 安装成功了。 - Thilo
3
@Thilo 我想你是指 --with-sqlite3-dir=,即 gem install sqlite3 -- --with-sqlite3-dir=/usr/local - tardate

11
在Ubuntu上:
sudo apt-get install libsqlite3-dev

那么运行 bundle install 命令就可以了。


6

在基于 Red Hat 的系统上,安装 "sqlite-devel" 软件包可以构建 "sqlite3" gem 的本地扩展。

在基于 Debian 的系统上,安装 "libsqlite3-dev" 软件包。


sqlite-devel已经安装: rpm -qa | grep sqlite-devel sqlite-devel-3.3.6-5 sqlite-devel-3.3.6-5 - Striketh
你是在尝试安装 'sqlite3-ruby' 或者 'sqlite3' gem 吗?建议使用 'Sqlite3'。 - Andrei Petrenko
啊,我想通了。我的包配置路径中的引号弄乱了一切。现在,我已经成功安装它了。 - Striketh

2

在CentOS上,您可以使用yum(已验证可用)

yum install sqlite sqlite-devel
gem install sqlite3

1
“gem sqlite3”需要sqlite 3.6.16+。CentOS只有v3.3.6。
因此,CentOS用户需要:
wget "http://www.sqlite.org/sqlite-autoconf-3071000.tar.gz"

然后,解压并执行:

cd sqlite-autoconf-3071000
./configure --prefix=/usr/local/sqlite-3.7   
make 
make && install

然后再尝试运行 gem install sqlite3 命令。


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