kubo / ruby-oci8

Ruby-oci8 - Oracle interface for ruby
Other
169 stars 75 forks source link

No such file or directory - oci8lib_230.so (LoadError) #193

Closed sameekhan closed 6 years ago

sameekhan commented 6 years ago

Hey Kubo,

I've been struggling with this issue: libmql1.so: cannot open shared object file: No such file or directory - /var/lib/gems/2.3.0/gems/ruby-oci8-2.2.5.1/lib/oci8lib_230.so (LoadError) when I navigate to that path the file does in fact exist.

I'm running on ubuntu 16.04. I followed the directions here:https://stackoverflow.com/questions/20084783/how-to-install-ruby-oci8-the-ruby-client-for-oracle-on-debian-based-systems-al and here: https://www.rubydoc.info/github/kubo/ruby-oci8/file/docs/install-instant-client.md

I downloaded it via gem install using the root user. I tried it against instantclient_12_2 and instantclient_12_1 with no luck.

Have you seen this before? What steps can I take to fix it?

kubo commented 6 years ago

libmql1.so: cannot open shared object file: No such file or directory - /var/lib/gems/2.3.0/gems/ruby-oci8-2.2.5.1/lib/oci8lib_230.so (LoadError)

libmql1.so is included in instantclient packages. Could you check the directory where libclntsh.so exists?

sameekhan commented 6 years ago

It lives in the directory /opt/oracle/instantclient_12_1 along with libmql1.so.

kubo commented 6 years ago

@beardaintweird Could you post the output of the following commands?

ls -l /opt/oracle/instantclient_12_1
ldd /var/lib/gems/2.3.0/gems/ruby-oci8-2.2.5.1/lib/oci8lib_230.so
readelf -d /var/lib/gems/2.3.0/gems/ruby-oci8-2.2.5.1/lib/oci8lib_230.so
sameekhan commented 6 years ago

@kubo ls -l /opt/oracle/instantclient_12_1

-rw-rw-r-- 1 root root       440 Jul  7  2014 BASIC_README
-rw-rw-r-- 1 root root       444 Jul  7  2014 SQLPLUS_README
-rwxrwxr-x 1 root root     29404 Jul  7  2014 adrci
-rwxrwxr-x 1 root root     43944 Jul  7  2014 genezi
-r-xr-xr-x 1 root root       342 Jul  7  2014 glogin.sql
lrwxrwxrwx 1 root root        16 Jun 13 16:21 lbclntsh.so -> lbclntsh.so.12.1
lrwxrwxrwx 1 root root        17 Jun 13 16:23 libclntsh.so -> libclntsh.so.12.1
-rwxrwxr-x 1 root root  58793741 Jul  7  2014 libclntsh.so.12.1
-rwxrwxr-x 1 root root   6990875 Jul  7  2014 libclntshcore.so.12.1
-r-xr-xr-x 1 root root   1768370 Jul  7  2014 libipc1.so
-r-xr-xr-x 1 root root    544150 Jul  7  2014 libmql1.so
-r-xr-xr-x 1 root root   6213011 Jul  7  2014 libnnz12.so
-rwxrwxr-x 1 root root   2576030 Jul  7  2014 libocci.so.12.1
-rwxrwxr-x 1 root root 109549133 Jul  7  2014 libociei.so
-r-xr-xr-x 1 root root    156353 Jul  7  2014 libocijdbc12.so
-r-xr-xr-x 1 root root    337137 Jul  7  2014 libons.so
-rwxrwxr-x 1 root root    118491 Jul  7  2014 liboramysql12.so
-r-xr-xr-x 1 root root   1546540 Jul  7  2014 libsqlplus.so
-r-xr-xr-x 1 root root   1564082 Jul  7  2014 libsqlplusic.so
-r--r--r-- 1 root root   3692096 Jul  7  2014 ojdbc6.jar
-r--r--r-- 1 root root   3698857 Jul  7  2014 ojdbc7.jar
drwxrwxr-x 5 root root      4096 Jul  7  2014 sdk
-r-xr-xr-x 1 root root      9581 Jul  7  2014 sqlplus
-rwxrwxr-x 1 root root    227410 Jul  7  2014 uidrvci
-rw-rw-r-- 1 root root     71202 Jul  7  2014 xstreams.jar

ldd /var/lib/gems/2.3.0/gems/ruby-oci8-2.2.5.1/lib/oci8lib_230.so

    linux-vdso.so.1 (0x00007ffc66a98000)
    libruby-2.3.so.2.3 => /usr/lib/x86_64-linux-gnu/libruby-2.3.so.2.3 (0x00007f5b13584000)
    libclntsh.so.12.1 => /opt/oracle/instantclient_12_1/libclntsh.so.12.1 (0x00007f5b105c7000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f5b103aa000)
    libgmp.so.10 => /usr/lib/x86_64-linux-gnu/libgmp.so.10 (0x00007f5b10127000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f5b0ff23000)
    libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007f5b0fceb000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f5b0f9e7000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5b0f648000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f5b13c40000)
    libmql1.so => /opt/oracle/instantclient_12_1/libmql1.so (0x00007f5b0f3d2000)
    libipc1.so => /opt/oracle/instantclient_12_1/libipc1.so (0x00007f5b0f054000)
    libnnz12.so => /opt/oracle/instantclient_12_1/libnnz12.so (0x00007f5b0e94a000)
    libons.so => /opt/oracle/instantclient_12_1/libons.so (0x00007f5b0e705000)
    libnsl.so.1 => /lib/x86_64-linux-gnu/libnsl.so.1 (0x00007f5b0e4ed000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f5b0e2e5000)
    libaio.so.1 => /lib/x86_64-linux-gnu/libaio.so.1 (0x00007f5b0e0e3000)
    libclntshcore.so.12.1 => /opt/oracle/instantclient_12_1/libclntshcore.so.12.1 (0x00007f5b0db71000)

readelf -d /var/lib/gems/2.3.0/gems/ruby-oci8-2.2.5.1/lib/oci8lib_230.so


Dynamic section at offset 0x2fcd8 contains 32 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libruby-2.3.so.2.3]
 0x0000000000000001 (NEEDED)             Shared library: [libclntsh.so.12.1]
 0x0000000000000001 (NEEDED)             Shared library: [libpthread.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libgmp.so.10]
 0x0000000000000001 (NEEDED)             Shared library: [libdl.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libcrypt.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libm.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [ld-linux-x86-64.so.2]
 0x000000000000001d (RUNPATH)            Library runpath: [/opt/oracle/instantclient_12_1]
 0x000000000000000c (INIT)               0xaf68
 0x000000000000000d (FINI)               0x245ac
 0x0000000000000019 (INIT_ARRAY)         0x22e9c8
 0x000000000000001b (INIT_ARRAYSZ)       8 (bytes)
 0x000000000000001a (FINI_ARRAY)         0x22e9d0
 0x000000000000001c (FINI_ARRAYSZ)       8 (bytes)
 0x000000006ffffef5 (GNU_HASH)           0x1f0
 0x0000000000000005 (STRTAB)             0x3dd8
 0x0000000000000006 (SYMTAB)             0x9d0
 0x000000000000000a (STRSZ)              7963 (bytes)
 0x000000000000000b (SYMENT)             24 (bytes)
 0x0000000000000003 (PLTGOT)             0x22ff18
 0x0000000000000007 (RELA)               0x6210
 0x0000000000000008 (RELASZ)             19800 (bytes)
 0x0000000000000009 (RELAENT)            24 (bytes)
 0x000000000000001e (FLAGS)              BIND_NOW
 0x000000006ffffffb (FLAGS_1)            Flags: NOW
 0x000000006ffffffe (VERNEED)            0x6150
 0x000000006fffffff (VERNEEDNUM)         4
 0x000000006ffffff0 (VERSYM)             0x5cf4
 0x000000006ffffff9 (RELACOUNT)          169
 0x0000000000000000 (NULL)               0x0
kubo commented 6 years ago

It looks correct.

ldd /var/lib/gems/2.3.0/gems/ruby-oci8-2.2.5.1/lib/oci8lib_230.so

...
libmql1.so => /opt/oracle/instantclient_12_1/libmql1.so (0x00007f5b0f3d2000)
...

libmql1.so should be found when oci8lib_230.so is loaded according to the result. I have no idea why libmql1.so cannot be opened. Well, how did you get the message? Does the following command run?

ruby -roci8 -e "p OCI8"

If it prints the message, could you run the following command? (Run sudo apt-get install strace if strace command doesn't exist.)

strace -e trace=open -o strace.log ruby -roci8 -e "p OCI8"
grep libmql1.so strace.log
sameekhan commented 6 years ago

@kubo

Can't run either command because of this error: /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:inrequire': libmql1.so: cannot open shared object file: No such file or directory - /var/lib/gems/2.3.0/gems/ruby-oci8-2.2.5.1/lib/oci8lib_230.so (LoadError) from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in require' from /var/lib/gems/2.3.0/gems/ruby-oci8-2.2.5.1/lib/oci8.rb:107:in<top (required)>' from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in require' from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:inrescue in require' from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:40:in require' I have a docker container* that I use as an executable to run ruby cucumber tests. Anytime I try to run this container it gives me the above error.

*Could running in a docker container be a part of the problem?

kubo commented 6 years ago

@beardaintweird Could you post the output of grep libmql1.so strace.log? strace.log is created by trace -e trace=open -o strace.log ruby -roci8 -e "p OCI8". It checks what directories are searched when trying to find libmql1.so.

In addition to it, could you run grep libclntsh.so strace.log to confirm the directory where libclntsh.so.12.1 exists?

I have not used docker containers and cucumber. I don't know docker-specific issues.

sameekhan commented 6 years ago

Sorry I thought that it wasn't allowing me to run the command, but it seems there is some output saved in the strace.log file.

open("/lib/x86_64-linux-gnu/tls/x86_64/libmql1.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/tls/libmql1.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/x86_64/libmql1.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libmql1.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/tls/x86_64/libmql1.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/tls/libmql1.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/x86_64/libmql1.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/libmql1.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/lib/tls/x86_64/libmql1.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/lib/tls/libmql1.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/lib/x86_64/libmql1.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/lib/libmql1.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/tls/x86_64/libmql1.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/tls/libmql1.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64/libmql1.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/libmql1.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
kubo commented 6 years ago

It's curious. oci8lib_230.so has the RUNPATH attribute whose value is /opt/oracle/instantclient_12_1. So /opt/oracle/instantclient_12_1/libmql1.so is checked before /lib/x86_64-linux-gnu/tls/x86_64/libmql1.so and so on. Could you post strace.log to https://gist.github.com/ and tell me the URL.

sameekhan commented 6 years ago

@kubo Here is the gist page you requested: https://gist.github.com/beardaintweird/f2d31bab06911cca11792a75359012fd

kubo commented 6 years ago

Thanks for posting the log. I have misunderstood RUNPATH.

In the Rpath page in wikipadia:

The ld dynamic linker does not search DT_RUNPATH locations for transitive dependencies, unlike DT_RPATH.

oci8lib_230.so depends on libclntsh.so.12.1.
libclntsh.so.12.1 depends on libmql1.so.

When oci8lib_230.so has a RPATH attribute pointing to /opt/oracle/instantclient_12_1, the directory is referred to search both libclntsh.so.12.1 and libmql1.so.
When oci8lib_230.so has a RUNPATH attribute pointing to /opt/oracle/instantclient_12_1, the direcotry is referred to search only libclntsh.so.12.1. So libmql1.so isn't found. This is your case.

There are three solutions.

  1. Set the environment variable LD_LIBRARY_PATH=/opt/oracle/instantclient_12_1 before a ruby process starts. Note that setting the variable in a process has no effect to the process itself.
  2. Append /opt/oracle/instantclient_12_1 to /etc/ld.so.conf or create a file containing /opt/oracle/instantclient_12_1 under /etc/ld.so.conf.d if the directory exists. Then run sudo ldconfig to update /etc/ld.so.cache.
  3. Recompile oci8lib_230.so without --enable-new-dtags linker option in order to set RPATH instead of RUNPATH. The linker option isn't usually passed to the linker when creating extension libraries. I guess that your /usr/lib/x86_64-linux-gnu/ruby/2.3.0/rbconfig.rb is customized.
kubo commented 6 years ago

@beardaintweird Is your issue solved by the previous solutions? Could I close this?

sameekhan commented 6 years ago

Yes, your help led me to the solution! Thank you so much!