On Sun, 29 Oct 2000, kason wong wrote:
> Hi,
>
> Can i load more than one library in jni? I have 4 lib used in my program:
> System.loadLibrary("pthread");
> System.loadLibrary("util");
> System.loadLibrary("cops");
> System.loadLibrary("COPS");
>
> and i 've got this error msg when i run my program
> Exception in thread "main" java.lang.UnsatisfiedLinkError: /home/kw
> ong/thesis/codes/libutil.so: /home/kwong/thesis/codes/libutil.so: undefined symbol:
>pthread_cond_timedwait
Yes, you can, but each library must not have any undefined symbols within it.
You must be able to run 'ldd -r libyourlib.so' and not see any unresolved
symbols. If there are, you either have a typo in your c (I typically
forget the env-> pointer on JNI calls) or you've left a library off your
-l list on the compile/link step.
Here's what ldd -r on my library looks like:
[joi@joi lib]$ ldd -r libjsystem.so
/home/joi/lib/libnat.so => /home/joi/lib/libnat.so (0x40004000)
/home/joi/lib/libsystem.so => /home/joi/lib/libsystem.so (0x4000d000)
/home/joi/lib/libudpmsg.so => /home/joi/lib/libudpmsg.so (0x4001d000)
/home/joi/lib/libuser.so => /home/joi/lib/libuser.so (0x40025000)
/home/joi/lib/libvoip.so => /home/joi/lib/libvoip.so (0x40032000)
libc.so.6 => /lib/libc.so.6 (0x40044000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x80000000)
If I'm guessing correctly, you're thinking that if COPS depends upon pthread,
your load order will resolve pthread symbols in COPS. I don't think it will.
I think you must resolve all of the symbols first, and load the final result
with loadLibrary.
A failing report would look like this:
[joi@joi lib]$ ldd -r libnat.so
statically linked
undefined symbol: nsSendNatMessage (./libnat.so)
undefined symbol: nsSendNatMessage (./libnat.so)
undefined symbol: nsSendNatMessage (./libnat.so)
...
But then libnat.so is the c library, not the jni loadable library.
If you see any undefined symbol messages in your jni loadable library, it
won't load.
That's why I'm doing in my makefile. In actuality there are about 6 libraries
involved in my build of libjsystem, but I trimmed them to shorten the attached
Makefile in my previous message. They only appeared as extra dependancies
and were built using the suffice rule, so I felt their presence would only
clutter the information. But libsystem.so actually needs bits of each for
some calls to resolve during the link step.
--
Joi Ellis Software Engineer
Aravox Technologies [EMAIL PROTECTED], [EMAIL PROTECTED]
No matter what we think of Linux versus FreeBSD, etc., the one thing I
really like about Linux is that it has Microsoft worried. Anything
that kicks a monopoly in the pants has got to be good for something.
- Chris Johnson
----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]