首页 > 解决方案 > 在 Linux 上安装 ruby​​-oci8 时无法编译 OCI 错误

问题描述

cannot compile OCI在 linux 上安装 ruby​​-oci8 时出现错误我使用的命令是我gem install ruby-oci8 -v '2.2.7' 正在使用 oracle 完整客户端

[root@advlints01 redf]# gem install 'ruby-oci8' -v '2.2.7'
Building native extensions. This could take a while...
ERROR:  Error installing ruby-oci8:
        ERROR: Failed to build gem native extension.

    current directory: /usr/local/rvm/gems/ruby-2.5.1@real_estate_fund/gems/ruby-oci8-2.2.7/ext/oci8
/usr/local/rvm/rubies/ruby-2.5.1/bin/ruby -I /usr/local/rvm/rubies/ruby-2.5.1/lib/ruby/site_ruby/2.5.0 -r ./siteconf20190916-29697-1loq660.rb extconf.rb
checking for load library path...
  LD_LIBRARY_PATH...
    checking /oracle/app/oracle/product/12.2.0/client_1/lib...   skip: /oracle/app/oracle/product/12.2.0/client_1/lib/libclntsh.so.12.1 is for i386 cpu.
  checking ld.so.conf... no
checking for cc... ok
checking for gcc... yes
checking for LP64... yes
checking for sys/types.h... yes
checking for ruby header... ok
Get the version of Oracle from SQL*Plus... 1220
try  -I/oracle/app/oracle/product/12.2.0/client_1/rdbms/public
checking for oci.h... yes
checking for OCIEnvCreate() in oci.h... no
*** 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/local/rvm/rubies/ruby-2.5.1/bin/$(RUBY_BASE_NAME)
        --with-instant-client
        --without-instant-client
/usr/local/rvm/gems/ruby-2.5.1@real_estate_fund/gems/ruby-oci8-2.2.7/ext/oci8/oraconf.rb:755:in `initialize': RuntimeError (RuntimeError)
        from /usr/local/rvm/gems/ruby-2.5.1@real_estate_fund/gems/ruby-oci8-2.2.7/ext/oci8/oraconf.rb:269:in `new'
        from /usr/local/rvm/gems/ruby-2.5.1@real_estate_fund/gems/ruby-oci8-2.2.7/ext/oci8/oraconf.rb:269:in `get'
        from extconf.rb:22:in `<main>'
---------------------------------------------------
Error Message:
  cannot compile OCI
Backtrace:
  /usr/local/rvm/gems/ruby-2.5.1@real_estate_fund/gems/ruby-oci8-2.2.7/ext/oci8/oraconf.rb:755:in `initialize'
  /usr/local/rvm/gems/ruby-2.5.1@real_estate_fund/gems/ruby-oci8-2.2.7/ext/oci8/oraconf.rb:269:in `new'
  /usr/local/rvm/gems/ruby-2.5.1@real_estate_fund/gems/ruby-oci8-2.2.7/ext/oci8/oraconf.rb:269:in `get'
  extconf.rb:22:in `<main>'
---------------------------------------------------
See:
 * http://www.rubydoc.info/github/kubo/ruby-oci8/file/docs/install-full-client.md for Oracle full client
 * http://www.rubydoc.info/github/kubo/ruby-oci8/file/docs/install-instant-client.md for Oracle instant client
 * http://www.rubydoc.info/github/kubo/ruby-oci8/file/docs/install-on-osx.md for OS X
 * http://www.rubydoc.info/github/kubo/ruby-oci8/file/docs/report-installation-issue.md to report an issue.


To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /usr/local/rvm/gems/ruby-2.5.1@real_estate_fund/extensions/x86_64-linux/2.5.0/ruby-oci8-2.2.7/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /usr/local/rvm/gems/ruby-2.5.1@real_estate_fund/gems/ruby-oci8-2.2.7 for inspection.
Results logged to /usr/local/rvm/gems/ruby-2.5.1@real_estate_fund/extensions/x86_64-linux/2.5.0/ruby-oci8-2.2.7/gem_make.out
[root@advlints01 redf]#





标签: ruby-on-railsoracle

解决方案


Looks like I found the cause of the issue. Im running arch linux (manjaro 18 xfce), there is a specific to arch linux oracle installation process using makepkg and pacman, so, everything goes ok with oracle-xe package and after installing it I can run sqlplus and connect to xe database which is a database created by default (usually), but I was not able to compile ruby-oci8 gem (2.2.8 v), after some researches I've found out that the problem were missing links in $ORACLE_HOME/lib folder:

libclntsh.so -> libclntsh.so.11.1 and libocci.so -> libocci.so.11.1

11.1 is a lib version (it depends on oracle version, eg. 11.2, 19.5 and etc.)

After creating these links via ln -s under oracle user, ruby-oci8 can be compiled.

Note: I'm using a full oracle client instead of instant one and all the guides do not say a word about linking these .so files but all the guides related to instant client do say it =D, here is a guide from developer of ruby-oci8 - instant client installation


推荐阅读