我的主数据库是一个本地 mysql 数据库,但是我偶尔会想在我的应用程序代码中直接连接到 Oracle 数据库。
oracle 数据库托管在另一台 RHEL 服务器上。
我没有成功尝试安装 ruby-OCI8 gem(错误:无法构建 gem native 扩展。)
我想知道 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 */
最佳答案
首先你需要安装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 数据库。
我已发布说明 how to install ruby-oci8 on Mac OS X - 其中大部分也适用于 Linux(Mac 上的 DYLD_LIBRARY_PATH 对应于 Linux 上的 LD_LIBRARY_PATH)。
此外我还创建了Sprinkle recipe for automated Oracle client installation on Linux - 这可能不是开始的最佳方式,但如果您想构建自动服务器安装脚本,那么您可以看看它。
关于ruby-on-rails - Ruby on Rails Oracle 数据库连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4496651/