2

我的主数据库是本地 mysql 数据库,但是我偶尔想在我的应用程序代码中直接连接到 Oracle 数据库。

oracle 数据库托管在另一个 RHEL 服务器上。

我尝试安装 ruby​​-OCI8 gem 失败(错误:无法构建 gem 原生扩展。)

我想知道 oracle 数据库是否必须是本地的才能使用这个 gem,或者是否有更好的方法来实现这一点。

gem install ruby-oci8

Building native extensions.  This could take a while...
ERROR:  Error installing ruby-oci8:
        ERROR: Failed to build gem native extension.

/usr/bin/ruby extconf.rb
checking for load library path...
  LD_LIBRARY_PATH...
    checking /opt/instantclient... yes
  /opt/instantclient/libclntsh.so.11.1 looks like an instant client.
checking for cc... *** 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=/usr/bin/ruby
        --with-instant-client
        --without-instant-client
./oraconf.rb:562:in `check_cc': RuntimeError (RuntimeError)
        from ./oraconf.rb:549:in `init'
        from ./oraconf.rb:1001:in `initialize'
        from ./oraconf.rb:343:in `new'
        from ./oraconf.rb:343:in `get'
        from extconf.rb:18
ng
---------------------------------------------------
Error Message:
  C compiler doesn't work correctly.
Backtrace:
  ./oraconf.rb:562:in `check_cc'
  ./oraconf.rb:549:in `init'
  ./oraconf.rb:1001:in `initialize'
  ./oraconf.rb:343:in `new'
  ./oraconf.rb:343:in `get'
  extconf.rb:18
---------------------------------------------------
See:
 * http://ruby-oci8.rubyforge.org/en/HowToInstall.html
 * http://ruby-oci8.rubyforge.org/en/ReportInstallProblem.html

我检查了 mkmf.log 文件:

 "gcc -o conftest -I. -I/usr/lib64/ruby/1.8/x86_64-linux -I.   -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fs    tack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fno-strict-aliasing  -fPIC conftest.c  -L. -L/usr/lib64 -L.      -rdynamic -Wl,-export-dynamic     -lruby-static  -lpthread -lrt -ldl -lcrypt -lm   -lc"
  /usr/bin/ld: skipping incompatible /usr/lib/libruby-static.a when searching for -lruby-static
  /usr/bin/ld: cannot find -lruby-static
  collect2: ld returned 1 exit status
  checked program was:
  /* begin */
  1: int main() { return 0; }
  8 /* end */
4

3 回答 3

0

首先您需要安装Oracle Instant Client - 选择相应的 Linux 32 位或 64 位二进制文​​件。为了安全起见,请使用我在所有 Ruby 和 Oracle 项目中使用的旧版本 10.2.0.4。安装 Basic、SDK 和 SQL*Plus 包。

然后在 LD_LIBRARY_PATH 环境变量中包含 Oracle Instant Client 安装目录,以便 Oracle Instant Client 动态库位于加载路径中。

然后尝试安装 ruby​​-oci8 gem。

然后安装activerecord-oracle_enhanced-adapter gem 以便能够从 ActiveRecord 访问 Oracle 数据库。

我已经发布了如何在 Mac OS X 上安装 ruby​​-oci8 的说明——其中大部分也适用于 Linux(Mac 上的 DYLD_LIBRARY_PATH 对应于 Linux 上的 LD_LIBRARY_PATH)。

此外,我还创建了用于在 Linux 上自动安装 Oracle 客户端的 Sprinkle 配方——这可能不是最好的开始方式,但如果你想构建自动服务器安装脚本,那么你可以看看它。

于 2010-12-21T12:37:25.537 回答
0

您可以像下面这样安装 ruby​​-oci8 gem,

LD_LIBRARY_PATH=/local/home/soundar/instantclient_11_2 gem install ruby​​-oci8

注意:LD_LIBRARY_PATH 是 oracle 即时客户端目录路径设置的环境变量

于 2012-11-16T11:15:00.517 回答
0

看看这篇博文是否能帮助您完成 OCI gem 安装http://jessehu.wordpress.com/2008/07/03/ruby-oci8-gem-available-2/

于 2010-12-21T07:23:32.377 回答