Re: Running Java applications with C libraries trough JNI on HP-UX



On 17 Nov 2006 03:32:29 -0800, Krystian wrote:
When i load with System.load with full path to the library it is loaded
and works ok.

That means there's nothing wrong with the library you built, and that
it has no unresolved dependencies preventing it from loading properly.

I suspect your use of System.loadLibrary() is wrong. What is the full
name of the library, and what is the argument you pass loadLibrary()?

Can you get it to work by setting (and exporting) SHLIB_PATH?

Try running your program under strace or truss or similar, to see
exactly what file the JVM is searching for. For example, here is what
strace tells me System.loadLibrary("foo") is doing on my Linux system:

$ cat Foo.java
public class Foo {
public static void main(String[] args) throws Exception {
System.out.println("java.library.path contains:");
System.out.println(System.getProperty("java.library.path"));
System.out.println();
System.loadLibrary("foo");
}
}

$ strace -o strace.txt java Foo
java.library.path contains:
/usr/local/pgm/jdk1.5.0_09/jre/lib/i386/client:/usr/local/pgm/jdk1.5.0_09/jre/lib/i386:/usr/local/pgm/jdk1.5.0_09/jre/../lib/i386

Exception in thread "main" java.lang.UnsatisfiedLinkError: no foo in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1682)
at java.lang.Runtime.loadLibrary0(Runtime.java:822)
at java.lang.System.loadLibrary(System.java:993)
at Foo.main(Foo.java:7)

Afterwards, strace.txt contains:

[...]
stat64("/usr/local/pgm/jdk1.5.0_09/jre/lib/i386/libfoo.so", 0xfeffcc68) = -1 ENOENT
stat64("/usr/local/pgm/jdk1.5.0_09/jre/lib/i386/client/libfoo.so", 0xfeffcc68) = -1 ENOENT
stat64("/usr/local/pgm/jdk1.5.0_09/jre/lib/i386/libfoo.so", 0xfeffcc68) = -1 ENOENT
stat64("/usr/local/pgm/jdk1.5.0_09/jre/../lib/i386/libfoo.so", 0xfeffcc68) = -1 ENOENT
[...]
write(2, "Exception in thread \"main\" ", 27) = 27
write(2, "java.lang.UnsatisfiedLinkError: "..., 59) = 59

/gordon

--
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
.



Relevant Pages

  • Re: Running Java applications with C libraries trough JNI on HP-UX
    ... Try running your program under strace or truss or similar, ... $ strace -o strace.txt java Foo ... Exception in thread "main" java.lang.UnsatisfiedLinkError: ...
    (comp.lang.java.programmer)
  • Re: To check or not to check for NULL?
    ... Other Throwables, Exceptions and RuntimeExceptions, are for problems, possibly serious, that a reasonable application should try to catch. ... Not only can it throw any checked exception declared in the signature, it can throw an unchecked exception, intentionally or unintentionally. ... public Foo(String arg) ...
    (comp.lang.java.programmer)
  • Could not load file or assembly every few days - asp.net 1.1
    ... Could not load file or assembly 'Foo, Version=1.0.2388.18427, ... An unhandled exception occurred during the execution of the ... Please review the stack trace for more information about ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Having to "print" before method invocation?
    ... Hey Fredrik, thanks for responding. ... foo that I've been using without much fuss for a few months now. ... if I add print statements before trying to invoke methods on ... the interpreter won't raise the exception immediately (since it expected you to ...
    (comp.lang.python)
  • Destructors and exceptions
    ... locals appears to be deferred to program exit. ... The only rationale I can think of is to speed up exception ... class Foo: ... def premature_exit: ...
    (comp.lang.python)