0

I am compiling a library in C/C++ with mingw32 that will be used by a java application.

The problem is that i get the error message java.lang.UnsatisfiedLinkError when the java calls the function in the library. Further investigation into the library (with nm) shows me that the symbol which needs to be called is incorrect.

Instead getting the symbol _Java_foo_function, the symbol saw in the library is _Java_foo_function@12.

So, can you help me to get rid of this issue ?

For your information, I tried to compile the same library under linux using GCC and the error does not appear.

Willi Mentzel
  • 27,862
  • 20
  • 113
  • 121
ZarLate
  • 1
  • 1
  • This seems related: http://stackoverflow.com/questions/1992722/g-how-to-unmangle-exported-symbols – Michael Jul 29 '15 at 08:32
  • I just saw the the post related http://stackoverflow.com/questions/1992722/g-how-to-unmangle-exported-symbols and added the option `-Wl,--add-stcall-alias` but it doesn't work either. – ZarLate Jul 29 '15 at 09:23
  • How about showing some code? Maybe you forgot the export specifier? – Youka Jul 29 '15 at 09:43
  • Here is some code : `JNIEXPORT void JNICALL _Java_foo_function (JNIEnv *, jobject);` I don't know what could be wrong since it works correctly under linux using GCC. – ZarLate Jul 29 '15 at 09:45
  • @ZarLate When you say "doesn't work either" do you mean that you still see the suffix after the symbol name? Been a while since I used mingw, but I recall often having to deal with issues related to spaces in the paths. Could be something to look into. – Alain Jul 29 '15 at 19:23
  • @Alain, When I say "it doesn't work either", I mean that the suffix after the symbol is still here. I checked the paths, no spaces. – ZarLate Jul 30 '15 at 06:56
  • The `@NN` pattern is the stdcall decoration (which indicates the size of the function's arguments on the stack). If it works on linux then that means you need to focus on the platform-specific portions of your work, that means `JNIEXPORT`, `JNICALL`, setting `PATH` properly, etc. Are you certain that the JVM can actually find your library and load it properly with `System.load()`? Please include those details in your question. – technomage Jul 30 '15 at 17:57

0 Answers0