【问题标题】:Error installing sqlite3 gem via bundler通过捆绑程序安装 sqlite3 gem 时出错
【发布时间】:2011-10-14 17:55:42
【问题描述】:

我正在尝试在我的帐户上安装 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。
  • @Codeglot 在 CentOS 上?祝你好运:)。
  • @Striketh 除了 sqlite3,您还必须安装一些 sqlite3 开发库,不幸的是我不知道具体是哪些。在 debian 上它是 libsqlite3-dev 和 libsqlite3-0。
  • 该包已经安装在系统上,但是由于操作系统级别的sqlite版本已经过时了,我不能依赖它。我可以让 gem install sqlite3 工作 - 我需要确定是否有一个参数可以传递给 bundler 以修改 gcc 在哪里寻找所有内容,因为这就是阻止我通过 bundler 安装的所有原因

标签: ruby-on-rails ruby sqlite


【解决方案1】:

这是我已验证有效的解决方案。

.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

【讨论】:

  • 我在使用 sqlite 3.3.6、rails 3.0.9、gem 1.5.2 的 CentOS 主机上遇到相同的编译错误。我对系统具有 root 访问权限,并且我的 gem 在 /opt 中,所以我不确定如何应用您的修复程序。你能给我一个提示,可以帮助我编译这个吗?我需要安装 sqlite-autoconf 吗?我只是使用我的一个存储库中的包。
  • 仅供参考,gem sqlite3 需要 sqlite 3.6.16+。 CentOS 有 v3.3.6,它不适用于 gem。
  • 感谢有关 sqlite 版本要求的提示。从源代码编译并使用gem install sqlite3 -- --with-sqlite-dir=/usr/local 安装在 CentOS 上成功了。
  • @Thilo 我想你的意思是--with-sqlite3-dir=gem install sqlite3 -- --with-sqlite3-dir=/usr/local
【解决方案2】:

在 Ubuntu 上:

sudo apt-get install libsqlite3-dev

然后捆绑安装将起作用。

【讨论】:

    【解决方案3】:

    安装 "sqlite-devel" 包以在基于 RH 的系统上构建“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' 更可取。
    • 啊,我想通了。我的捆绑配置路径中的引号搞砸了。我现在已经成功安装了。
    【解决方案4】:

    在 CentOS 上,可以使用 yum(经过验证的作品)

    yum install sqlite sqlite-devel
    gem install sqlite3
    

    【讨论】:

      【解决方案5】:

      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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-06-15
        • 1970-01-01
        • 2011-08-09
        • 2012-04-17
        • 2014-07-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多