Saturday, February 27, 2021

SKP's Java/Java EE Gotchas: Java Native Interface (JNI): Unsatisfied Link Error

I Spent Almost Two Whole Days Trying To Solve This Issue. I Did Everything Possible From Altering My C++ Code (Changing The Return Types) To Compiling From Command Line Rather Than The IDE. Also, I Tried A Number Of Other Steps Like Changing The Classpath, Refactoring Package Names To Changing Names Of The Generated Header Files. Finally, I Found The Following Resolution.

Whenever the C++ Compiler (GCC) Generates a DLL, It is Exported in the Following Form:
  
Java_SomePackage_SomeClass_SomeNativeMethod@8
 

Where The Integer Suffix Suggests The Byte Space Required By The Arguments. This Sort Of Function Call Makes No Sense To The JVM (While Invoking Some Native Method) And Hence It Leads To java.lang.UnsatisfiedLinkError. The Resolution Is To Add The Following Flags While Linking To Generate Unmangled Names:



from DZone.com Feed https://ift.tt/3dSoust

No comments:

Post a Comment