user1400538
user1400538

Reputation: 865

java.lang.UnsatisfiedLinkError in Ubuntu

I have seen many posting this issue in SO. I have gone through those posts and tried out the suggested methods, but unfortunately could not help me resolve the issue.

Here is my problem:

public class runme {
  static {
    System.loadLibrary("example");
  }

  public static void main(String argv[]) {
    System.out.println(example.fact(4));


  }
}

Error:

anu@anu-desktop:~/Desktop/swigtest/new$ java runme
Exception in thread "main" java.lang.UnsatisfiedLinkError: no example in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1681)
    at java.lang.Runtime.loadLibrary0(Runtime.java:840)
    at java.lang.System.loadLibrary(System.java:1047)
    at runme.<clinit>(runme.java:5)
    Could not find the main class: runme. Program will exit.

The example library is in the same path as the runme.java. Why do I get this error then? I am working from Ubuntu OS.

Any help which would help me resolve this is much appreciated.

EDIT:

I have attached my files here

Upvotes: 2

Views: 6245

Answers (5)

Twaha Mehmood
Twaha Mehmood

Reputation: 737

You need to add/append the path to your shared library to the LD_LIBRARY_PATH like :

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path_to_folder_where_your_shared_library_is

Upvotes: 0

maba
maba

Reputation: 48105

Try to run your program like this:

$> java -Djava.library.path=/path/to/my/libs runme

Where /path/to/my/libs should be changed to where you really have your .so file(s).


Edit

I installed openjdk-6-jdk on my virtual Ubuntu machine to see where include files are.

Try this to get your libexample.so:

$> gcc -fPIC -g -c -Wall example_wrap.c -I/usr/lib/jvm/java-6-openjdk/include -I/usr/lib/jvm/java-6-openjdk/include/linux
$> gcc -shared -o libexample.so example_wrap.o

Then check that the file has been created...

Now you just have to call

$> java runme

The -Djava.library.path is not needed if the .so file is in the working directory.

Upvotes: 1

Ilan Tal
Ilan Tal

Reputation: 499

I ran into this problem on Ubuntu and solved it using a bat file

export LD_LIBRARY_PATH=$PWD/lib/linux32
./fiji-linux

The object which needs to be set is LD_LIBRARY_PATH and I set it to the local directory with the addition of /lib/linux32. The next line runs my program.

Upvotes: 0

Joonas Pulakka
Joonas Pulakka

Reputation: 36577

Even though the docs say that The manner in which a library name is mapped to the actual system library is system dependent, in my experience loadLibrary's relative path refers to the working directory (after which it checks all other defined and system-dependent paths).

If unsure about the working directory, check what System.getProperty("user.dir") returns.

Upvotes: 1

Some programmer dude
Some programmer dude

Reputation: 409482

You have to set the java.library.path property to include the path of your library. Or copy it to a location already in the path.

Upvotes: 1

Related Questions