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

K

Krystian

Hi,

i have compiled java application on HP-UX with native C library, but i
can't run
it!
Each time i get:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no uxinfo in
java.lib
rary.path

uxinfo is the name of my C library.

I can't get it to work!

I use:
java -Djava.library.path=. test

/test is the name of my test application which uses the library/

I've tried renaming the library from uxinfo.sl to uxinfo but still no
luck.

When i check the java.library.path with a small application:
public class GetProperty {
public static void main(String[] args) {
System.out.println(System.getProperty(args[0]));
System.exit(0);
}

}

i can see '.' amongst other directories...

Help, anyone?

Best regards,
Krystian
 
G

Gordon Beaton

Exception in thread "main" java.lang.UnsatisfiedLinkError: no uxinfo
in java.library.path

The message can be misleading. It means that the library failed to
load, not necessarily that it couldn't be found.

Loading will fail if your call to System.loadLibrary() incorrectly
specifies a path, or a system specific prefix or file extension.

It will fail if the file is not really a shared library (perhaps you
built it incorrectly). The first link below has examples of building a
shared library for JNI on HPUX.

It will fail if your library depends on other libraries that can't be
loaded. Note that java.library.path can't be used for this, the
dynamic linker/loader (e.g. ld.so) *must* be able to find them. For
that you need to set SHLIB_PATH, or re-configure the dynamic
linker/loader.

See if you can load the file with System.load(), specifying a full
path and filename to the library. This will eliminate some of the
alternatives.

Use "file" to see whether your system agrees that the file is a shared
library.

Use "ldd -v" or "objdump -p" to look for (missing) dependencies.

These might help:
http://www.hp.com/products1/unix/java/infolibrary/prog_guide/JNI_java2.html
http://www.faqs.org/faqs/hp/hpux-faq/section-277.html
http://docs.hp.com/en/B2355-91015/linkhelp.html

/gordon
 
K

Krystian

Gordon said:
The message can be misleading. It means that the library failed to
load, not necessarily that it couldn't be found.

Loading will fail if your call to System.loadLibrary() incorrectly
specifies a path, or a system specific prefix or file extension.

It will fail if the file is not really a shared library (perhaps you
built it incorrectly). The first link below has examples of building a
shared library for JNI on HPUX.

It will fail if your library depends on other libraries that can't be
loaded. Note that java.library.path can't be used for this, the
dynamic linker/loader (e.g. ld.so) *must* be able to find them. For
that you need to set SHLIB_PATH, or re-configure the dynamic
linker/loader.

See if you can load the file with System.load(), specifying a full
path and filename to the library. This will eliminate some of the
alternatives.

Use "file" to see whether your system agrees that the file is a shared
library.

Use "ldd -v" or "objdump -p" to look for (missing) dependencies.

These might help:
http://www.hp.com/products1/unix/java/infolibrary/prog_guide/JNI_java2.html
http://www.faqs.org/faqs/hp/hpux-faq/section-277.html
http://docs.hp.com/en/B2355-91015/linkhelp.html

/gordon

Hi Gordon,
thank You for reply.

I used the first link You wrote before, and did everything as HP stated
there.
For testing purposes i even tried to do same test application with
Hello world they did.
Unfortunately same problem:

# java -Djava.library.path=. TestJava2CallingNative
error: java.lang.UnsatisfiedLinkError: no cImpl in java.library.path



But i can see a little difference... they use aCC to compile the
library, but I don't have it. I used cc instead. Could this be the
case?
I used this command to compile the library:

cc -b -o libaCCImpl.sl cImpl.o \
-lstd -lstream -lCsup -lm

# file uxinfo.sl
uxinfo.sl: PA-RISC2.0 shared library -not stripped

I still don't know what's going on.

Best regards,
Krystian
 
G

Gordon Beaton

For testing purposes i even tried to do same test application with
Hello world they did. Unfortunately same problem:

# java -Djava.library.path=. TestJava2CallingNative
error: java.lang.UnsatisfiedLinkError: no cImpl in java.library.path

This doesn't agree with the name you used in your cc example, below.
I'd expect the error message to refer to "aCCImpl" instead:
I used this command to compile the library:

cc -b -o libaCCImpl.sl cImpl.o \
-lstd -lstream -lCsup -lm

# file uxinfo.sl
uxinfo.sl: PA-RISC2.0 shared library -not stripped

I still don't know what's going on.

Did you try loading with System.load("/full/path/to/libaCCImpl.sl")
like I suggested?

I don't have access to HPUX and can't tell you the difference between
aCC and cc on your system. I normally use gcc to compile and link.

/gordon
 
K

Krystian

Gordon said:
This doesn't agree with the name you used in your cc example, below.
I'd expect the error message to refer to "aCCImpl" instead:


Did you try loading with System.load("/full/path/to/libaCCImpl.sl")
like I suggested?

I don't have access to HPUX and can't tell you the difference between
aCC and cc on your system. I normally use gcc to compile and link.

/gordon
Thanks again.

I'm sorry for difference between examples, names are same.
When i load with System.load with full path to the library it is loaded
and works ok.
Unfortunately when loading with System.loadLibrary and giving full path
to th elibrary with -Djava.library.path= i've got still errors :/

Unfortunately i've got no gcc here, i used now ld to compile the
library.

Best regards,
Krystian
 
G

Gordon Beaton

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
 
K

Krystian

Gordon said:
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


Thanks a lot!
strace on hp-ux is something totally different then on linux/bsd, but
Your log file gave me an answer! When i've changed the name to
libuxinfo.sl java loaded it and it works /well...kind of..i have to
change something in my C code ;) /

Best regards,
Krystian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top