🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #2429

Re: jni and 'c' shared library

#2429
From: Joi Ellis [TeamB]
Date: Mon, 27 Nov 2000 00:00
39 lines
2302 bytes
E Steel <steel@tis4000.com> wrote:
[snip]
> All fies in the shared library were created with the gcc compiler with
> the -fpic flag set and -G on the ld command. The library is found, but
> when I reference one of the jni methods, snapInit, I get an "Unsatisfied
> link error snapInit", like it can not be found in the share library.
> However, when I do a Unix nm on the shared library, I can see the
> decorated name for this function in there. I hope I have given enough
> info. Any suggestions will be greatly appreciated.

Two things to check for first:

  Does 'ldd -r libwhatever.so' report any undefined symbols?  If it does,
it will cause unsatisfied link errors when the JVM executes the loadLibrary()
method.  I found that it's important to make sure you compile with gcc's
-shared option.  This is the only sort of library the JVM on linux will load,
and since the Linux JVM is a port of the Solaris JVM, I assume the Solaris JVM
has the same requirement.  (That's what my JNI references say as well, but I
haven't built any JNI on Solaris myself yet.)

  The other thing to check is that you've remembered to use the JNIenv pointer
to access your JNI methods within your C code.  If I write a JNI call
and forget to use that pointer, it compiles just fine, and the library
links okay, but ldd -r will show that method as an unresolved reference
and the JVM will throw the Unsatisfied link exception.

For example, if I am supposed to write

    const char *str = (*env)->GetStringUTFChars(env, input, 0);

But I mistakenly write

    const char *str = GetStringUTFChars(env, input, 0);
  
Then I'll get that same error.
-- 
Joi Ellis (TeamB) 
No direct email, please.
For best results, post on news server newsgroups.borland.com!
Technical Details
Message-ID: <8vu3l4$4on10@bornews.inprise.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <3A227B66.81D4D21A@tis4000.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1089d0,4b947bd6a39f36be
X-Google-Attributes: gid1089d0,public
From: "Joi Ellis [TeamB]" <joi@aravox.com>
Subject: Re: jni and 'c' shared library
Date: 2000/11/27
Message-ID: <8vu3l4$4on10@bornews.inprise.com>
X-Deja-AN: 698299568
References: <3A227B66.81D4D21A@tis4000.com>
Organization: Another Netscape Collabra Server User
User-Agent: tin/1.4.2-20000205 ("Possession") (UNIX) (Linux/2.2.14-5.0 (i686))
Newsgroups: borland.public.jbuilder.java.api