2010-12-21 267 views
2

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

oracle数据库位于另一个RHEL服务器上。

我unsuccessfull尝试安装红宝石OCI8宝石(错误:未能建立宝石原生扩展)

我想知道oracle数据库是否是为了使用这个宝石,或者如果本地有更好的方法来实现这一点。

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 */ 
+0

这已经离开了我最初的问题的整个点。我想知道OCI8插件是否适用于外部数据库,因为我似乎无法在任何地方放置主机名 – Rumpleteaser 2010-12-22 05:19:37

+0

“C编译器无法正常工作。”似乎看起来像一个问题。我尝试下载源代码并制作它。 – Rumpleteaser 2010-12-22 05:53:17

回答

0

首先,你需要安装Oracle Instant Client - 选择相应的Linux 32位或64位二进制文​​件。为了安全起见,我使用所有我的Ruby和Oracle项目中使用的旧版本10.2.0.4。安装基本,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(DYLD_LIBRARY_PATH在Mac上对应于Linux上的LD_LIBRARY_PATH)。

此外,我创建了Sprinkle recipe for automated Oracle client installation on Linux - 可能它不是以此开始的最佳方式,但如果您想构建自动服务器安装脚本,那么您可以查看它。

+0

我解压缩了我们的压缩文件,创建了所有未来升级所需的符号链接。导出路径并将它们放入bash配置文件中。我测试了oracle客户端,并且能够登录到数据库并进行搜索。宝石仍然不会安装。 – Rumpleteaser 2010-12-22 04:43:15

0

可以安装红宝石OCI8宝石像下面,

LD_LIBRARY_PATH = /本地的/ home/soundar/instantclient_11_2宝石安装红宝石OCI8

注:LD_LIBRARY_PATH是一个环境变量通过Oracle Instant客户端设置目录路径