Re: mingw32 and jdk/jni
Keith Marshall <[email protected]> Tue, 22 Sep 2020 22:20:24 +0100
| Newsgroups | gmane.comp.gnu.mingw.user |
|---|---|
| Organization | MinGW.org Project |
| Message-ID | <[email protected]> |
On 22/09/2020 05:11, Paul Edwards wrote: > using JNI. I am getting an error about not being > able to find _imp__JNI_CreateJavaVM@12 > > I have got conflicting information from the web > as to whether the jvm.lib that is supplied in the > JDK should work or not. Some information says > that it won't work, because the function is > stdcall and mingw32 does not prefix the function > name with an underscore, while MSVC does. Not true. Both mingw32 and MSVC 32-bit prepend one extra underscore to the symbol name, as it appears in C source code, to get the symbol name as it appears in object code, (object files and libraries). Confusion may arise w.r.t. mingw64 and MSVC 64-bit, neither of which prepends the underscore. C++ may also introduce potential for confusion, since the compiler will mangle any symbol name that is not declared to have extern "C" linkage. > Note that the above reference only has one > underscore, instead of the two that show up > when running "nm" on jvm.lib: > > 00000000 I __imp__JNI_CreateJavaVM@12 > U __IMPORT_DESCRIPTOR_jvm > 00000000 T _JNI_CreateJavaVM@12 That looks correct; compare the corresponding references for Microsoft's LoadLibraryA(), from our own libkernel32.a: $ nm mingw32/lib/libkernel32.a : 00000000 I __imp__LoadLibraryA@4 00000000 T _LoadLibraryA@4 : > I have tried a lot of searches and a lot of > experiments, but nothing successful. I still > can't even answer the basic question of > whether it is meant to work out of the box > or not. I am unaware of any reason why it shouldn't work, and no ... > Or whether I need to construct my own "lib" file. ... you already have an import library, which should work. > Any ideas? Relevant technical info below. Looks like the classical user error of getting the linking order utterly wrong! (It hasn't arisen recently, but used to come up regularly). > C:\paul\devel\jnitest>mingw32-make > mingw32-gcc -o mary.exe \ > -L "C:\Program Files (x86)\Java\jdk1.8.0_221\lib" \ > -ljvm \ This *is* wrong! The linker will read libjvm.a, (having searched for libjvm.dll.a, libjvm.a, and finally jvm.lib, in this order), *before* it has even started building its table of required symbol references, find that this library offers nothing which is required, (because *nothing* is required yet), and dismiss it as irrelevant, without considering it further. > -I "C:\Program Files (x86)\Java\jdk1.8.0_221\include" \ > -I "C:\Program Files (x86)\Java\jdk1.8.0_221\include\win32" \ > mary.c And only now, do you start building a table of required references, *after* jvm.lib has been dismissed as contributing nothing. > c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: > C:\Users\xxx\AppData\Local\Temp\ccqlQomh.o:mary.c:(.text+0x3c): > undefined reference to `_imp__JNI_CreateJavaVM@12' > collect2.exe: error: ld returned 1 exit status > Makefile:7: recipe for target 'mary.exe' failed > mingw32-make: *** [mary.exe] Error 1 I would expect this, because the linking order is *wrong*; the -ljvm reference *must* come *after* all .c or .o files which refer to it. > C:\paul\devel\jnitest>mingw32-gcc --version > mingw32-gcc (MinGW.org GCC-8.2.0-5) 8.2.0 You may wish to consider an upgrade ... we released a mingw32 GCC-9.2.0 in January 2020. > mary.c: > ret = JNI_CreateJavaVM(&jvm, (void**)&env, &args); It would have been useful if you had shown us whatever declaration of JNI_CreateJavaVM() is in scope, when this statement is compiled; we can address your enquiry more effectively, when we are given *all* of the pertinent information ... preferably as an SSCCE (see sscce.org). -- Regards, Keith. Public key available from keys.gnupg.net Key fingerprint: C19E C018 1547 DE50 E1D4 8F53 C0AD 36C6 347E 5A3F _______________________________________________ MinGW-Users mailing list [email protected] This list observes the Etiquette found at http://www.mingw.org/Mailing_Lists. We ask that you be polite and do the same. Disregard for the list etiquette may cause your account to be moderated. _______________________________________________ You may change your MinGW Account Options or unsubscribe at: https://lists.osdn.me/mailman/listinfo/mingw-users Also: mailto:[email protected]?subject=unsubscribe
signature.asc
(application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEwZ7AGBVH3lDh1I9TwK02xjR+Wj8FAl9qapgACgkQwK02xjR+ Wj9OMg//RhxHD5qMwOtFRsn+qe1AxVC/9TR31hH79wjZyT8h75cd+ckFD9SYrjVN LZJAErJe/xhQFEb1bWRPAPDpVm3VkNPh0hgGMoKfLgXSL2tv0BFiVV7lnOleq4yW OQPV2MyWyy5YfFihIuIaA9E9jz/3t6lzETnVffWXE9hr+1V4IOCwcnavLXhDzX8U S9Us+WB4mccaQwRGB+iJ3mNSPQj0XDWlNm6ahKwPHw4BfS3xkvpeloLP7Cg4ZWcl 7t7jcjgopiIdOA3f8yIbcOYyTJiwlmJ3wSc/twTmkdJk7EW/ChQuvI0wW54jpFk7 qymf6w4S9x8HbLyU6zwubtzDDNDuh6HrqHn7iLJjMg7LwBEgXPJwTkFMEz33zFoz 6ERi0/eTjSpCdKk25w06jGMef9Cuk2bb1WIoZtHczpMuUyYGZCnAq6I9QJD0HWGi WojF0UIsePwPzWZQ5LJNEaZfWamL/M15ZUtNaA5RlRwLRoZlY/V6CcnYMuMVCJvf +OFbDoGqCJODsw5iRgaYAhEGM2XAwvUhb+1c+o+ZE1IKUzl5RPAOa/8QPeVTziNH ei3NibeV26Ipuwj4mVaAFnAAcc1JiglEHnVi+alpej2tS7Zxlpm2G5JntMt5cFhq 0hDmJTre9lvqzOnCEhiigWuIYoZcPaEBm7JDTbYXAFR0O2CwhCY= =o8yw -----END PGP SIGNATURE-----