Why do I get an exception while calling a MATLAB compiled DLL from a JAVA/JNI application?

5 views (last 30 days)
I have compiled a C++ DLL using the MATLAB Compiler. When this DLL is called from a C/C++ client application, it works fine. However, when I try to call the Wrapper C++ via Java/JNI, I get the following error:
ERROR: Error occurred during initialization of VM
Unable to load native library: The specified procedure could not be found
Stack Trace:
[0] jmi.dll:void __stdcall mwJavaAbort(void)(0x0d8319d5, 0, 1024, 0x0d831ad0) + 21 bytes
[1] jvm.dll:0x0d86b0a7(0x0d8c9420 "Unable to load native library", 0x0d71eab4 "The specified procedure could no..", 0x0d8db36c, 0)
[2] jvm.dll:0x0d86a10a(0, 3014656, 0, 0)
[3] jvm.dll:0x0d8062c1(0, 0, 0x0adf0b30, 0x0adf0b30)
[4] jvm.dll:0x0d806a4a(0x0d8925cc, 0x0d83c7a3, 12, 0x7848d050)
[5] jvm.dll:0x0d8252ca(0x0d71fe80, 0x0d83c7a3, 0x7848d050, 0x0d71fee8 " ?q\r?\n?y")
[6] jvm.dll:0x0d83c7e8(0x79cd69c8, 0x0d71fed8, 0x0d71fe80, 0x7c3536ed)
[7] jmi.dll:struct JNIEnv_ * __cdecl InitSunVM(bool)(0, 0x79ccde48 "MATLAB_JDB", 0x0d71ff10, 0) + 1390 bytes
[8] jmi.dll:bool __cdecl InitJava(void)(0x7c3536ed, 0x793f3a74, 0x7c910222, 519076) + 103 bytes
[9] jmi.dll:bool __cdecl mljInit(void)(0x0be3b2b0, 1, 0x0be3a3c0 "C:\Program Files\MATLAB\MATLAB C..", 0x7940a170) + 6 bytes
[10] mcr.dll:unsigned long __cdecl run_init_and_handle_events(void *)(519076, 0x7c910222, 15, 519076) + 54 bytes
[11] kernel32.dll:0x7c80b699(0x793feac0, 519076, 0, 0x0d722820 " *r\r")
------------------------------------------------------------------------
Fatal Java Exception detected at Wed Jun 10 11:07:49 2009
------------------------------------------------------------------------

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 23 Apr 2023
Edited: MathWorks Support Team on 24 Apr 2023
This exception occurs because you cannot create two JVMs in the same process.
This information can be found under the "JNI_GetCreatedJavaVMs" title at the following link:
This means that when there is an existing JVM then the MATLAB Compiler Runtime (MCR) will attach to it.
The error stack in the log points to some library with the wrong interface being loaded.
jvm.dll:0x0d86b0a7(0x0d8c9420 "Unable to load native library", 0x0d71eab4 "The specified procedure could no..", 0x0d8db36c, 0)
Using tools like Dependency Walker (
) or Process Monitor (
) can give some more information.
Our product MATLAB Builder JA is designed specifically to use a deployed component from a Java application. For additional details about MATLAB Builder JA, please refer to the following link:
Please note that we can provide limited support in cases where a MATLAB compiled C++ DLL is called from a Java application, as we have a separate product designed for such a workflow.

More Answers (0)

Categories

Find more on C Shared Library Integration in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!