win32: Why exports of JNI_* symbols from _exe_ files

Danny Smith danny_r_smith_2001@yahoo.co.nz
Tue Aug 5 02:10:00 GMT 2003


 --- Jeff Sturm <jsturm@one-point.com> wrote: > On Tue, 5 Aug 2003, [iso-8859-1] Danny Smith
wrote:
> > Is there a reason for these symbols always to be exported from
> > .exe file?
>> Probably no good reason.
>> When jni.o is built, how can it know if its final destination is a
> .exe or .dll?
>*shrug*
 
> Jeff

Okay, here is the problem that motivated my question.
jni.h declares these symbols to user-land as __declspec(dllimport), so that will
create references to __imp__JNI*. 
Consider this:
The libarary:
/* foo.c */
void __declspec(dllexport) foo()
{ }
The client:
/* main.c */
extern __declspec(dllimport) void foo();
int main()
{
 foo();
 return 0;
}
gcc -c foo.c
gcc main.c foo.o 
D:\TEMP/ccWgaaaa.o(.text+0x1f):main.c: undefined reference to `_imp__foo'
Removing __declspec(dllimport) from the declaration of foo in main.c fixes.
Also, even if foo() does live in dll and has the __imp__ prefix, the 
dllimport attribute is not necessary and the fixup will occur in the dll.
Likewise, removing JNIIMPEXP attributes from declarations in jni.h will allow
userland code to reference the JNI_* symbols whether they live in dll or static lib.
I'm wondering if the JNIEXP attribute should also be removed from the definitions
in jni.cc. If you want to specify what goes into a .dll, can always use a .DEF file
when building the dll (or .exe for that matter).
Danny
http://personals.yahoo.com.au - Yahoo! Personals
- New people, new possibilities! Try Yahoo! Personals, FREE for a limited period!


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /