2010-12-21 268 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客戶端設置目錄路徑