5

I'm trying to compile a Java library that uses JNI. When I start the program, I see a crash with an UnsatisfiedLinkError, which says that a particular method could not be found in the DLL.

On closer inspection, I found out that g++, which I use for compilation and linking, mangled my method names by adding suffixes such as "@8" or "@16" to the method names. Does anybody know the correct compiler options to disable the name mangling? Thanks in advance!

EDIT: I'm using MinGW through Eclipse + CDT plugin.

python dude
  • 7,980
  • 11
  • 40
  • 53

1 Answers1

12

For JNI calls to work with Windows DLLs compiled with GCC you need to add a add-stdcall-alias parameter to GCC on linking phase:

gcc -Wl,--add-stdcall-alias

Which will add correct function names to the DLL and thus enable calls via JNI.

Mavrik
  • 2,580
  • 4
  • 19
  • 30
  • Thanks a lot! This has finally solved my problem. With this parameter, there's a decorated and an undecorated version for each method in the DLL, and the Java programs works :D – python dude Jan 02 '10 at 21:25
  • @Mavrik thank you for filling this in, I knew the problem but not the solution. – bmargulies Jan 02 '10 at 22:19
  • So this works for other cases than just underscores in mangled names? – mavavilj Dec 24 '22 at 11:25