Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Krystian - 17 Nov 2006 08:37 GMT
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
Gordon Beaton - 17 Nov 2006 09:16 GMT
> 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

Signature

[ 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

Krystian - 17 Nov 2006 10:19 GMT
> > Exception in thread "main" java.lang.UnsatisfiedLinkError: no uxinfo
> > in java.library.path
[quoted text clipped - 30 lines]
>
> /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
Gordon Beaton - 17 Nov 2006 10:30 GMT
> 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:
>
[quoted text clipped - 5 lines]
>
> 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

Signature

[ 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

Krystian - 17 Nov 2006 11:32 GMT
> > For testing purposes i even tried to do same test application with
> > Hello world they did. Unfortunately same problem:
[quoted text clipped - 22 lines]
>
> /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
Gordon Beaton - 17 Nov 2006 12:11 GMT
> 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

Signature

[ 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

Krystian - 17 Nov 2006 13:00 GMT
> > When i load with System.load with full path to the library it is loaded
> > and works ok.
[quoted text clipped - 43 lines]
>
> /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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.