Error while loading shared libraries; cannot open shared object file: No such file or directory
Asked Answered
A

2

6

I have problem when loading shared libraries (JNI) from java class on Ubuntu operator system

Exception in thread "main" java.lang.UnsatisfiedLinkError: /opt/ETcpsdk/lib/linux-x86_64/libjcryptoki.so: libcryptoki.so: cannot open shared object file: No such file or directory
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1965)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1890)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1880)
    at java.lang.Runtime.loadLibrary0(Runtime.java:849)
    at java.lang.System.loadLibrary(System.java:1088)
    at tutorialjni.Test.<clinit>(Test.java:7)

- Test.java

package tutorialjni;

public class Test {

    // Load an external library, called "jcryptoki"
    static {
        System.loadLibrary("jcryptoki");
    }

    public static void main(String[] args) {
        System.out.println(System.getProperty("java.library.path"));
    }

}

- LD_LIBRARY_PATH was allocated in /etc/environment

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
JAVA_HOME="/opt/jdk1.7.0_75"
LD_LIBRARY_PATH="/opt/ETcpsdk/lib/linux-x86_64:/opt/ETcpsdk/lib/"

And I own ETcpsdk folder.

  • libcryptoki.so put in /opt/ETcpsdk/lib/linux-x86_64/libcryptoki.so

  • Run file libcryptoki.so command

    libjcryptoki.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, not stripped

- JDK version:

java version "1.7.0_75"
Java(TM) SE Runtime Environment (build 1.7.0_75-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.75-b04, mixed mode)

- Ubuntu:

Distributor ID: Ubuntu
Description:    Ubuntu 14.04.2 LTS
Release:    14.04
Codename:   trusty

I added library directory to ldconfig cache

Can you help me?

Aluin answered 2/4, 2015 at 17:11 Comment(0)
A
2

I got this problem because my shared libraries depends on another shared library which works improperly.

Aluin answered 4/12, 2015 at 9:39 Comment(1)
i got the similar problem: Test.java depends on libfoo.so which depends on libbar.so. how did you solve it?Exsert
P
1

If you encounter this from Linux, there usually 3 main reasons:

  1. Your library depends on environment PATH.

Solution: Set your path variable at .bashrc so that it loads on starup. Reboot Linux or run . ~/.bashrc.

  1. Library file symbolic link broken. Linux apps used to create file as symbolic link in a centralized location than point them to actual file at dedicated path.

Solution: Check your library file if it exists as link and whether it points to a valid file.

  1. User's insufficient access rights.

I hit this error when my web app was started in Linux by user logged in with insufficient access rights. This error usually followed by other errors / exceptions, especially from your application server i.e for Tomcat:

org.apache.catalina.LifecycleException: Failed to initialize component ...

or

org.hibernate.engine.jdbc.internal.LobCreatorBuilder - HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException

Solution: Stop your web / application server current instance. Login with super user or those with sufficient access rights i.e root Restart your server or call previous function again.

Permeate answered 4/1, 2019 at 6:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.