Deploying Java Package - Error - Failed to find the library mclmcrrt7_16.dll

28 views (last 30 days)
Hi,
I've created a Java Package on Matlab. However, when try to call the created class from a java app, i get the error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Failed to find the library mclmcrrt7_16.dll, required by MATLAB Builder JA, on java.library.path. This library is typically installed along with MATLAB or the MCR, its absence may indicate an issue with that installation or the current path configuration. The MCR version that this component is trying to use is: 7.16.
I've checked the path environment variable and this dll is located one of the paths - ie. c:\Program Files\MATLAB\R2011b\runtime\win64.
A couple of things though. When i compile the java package using javac version 1.7.0_02 I don't get this problem. But when i change the path environment variable to point at version 1.6.0_29, this problem crops up. (I have to build using version 1.6 as I'm using repast java which runs on 1.6 - it kicks up lots of errors when i try to run my app using JRE 7/JSE 1.7).
ALso, I'm running the java app on the same machine that matlab was installed on.
Any ideas?
Thanks,
Eoin

Accepted Answer

Kyle White
Kyle White on 23 Mar 2012
Hi Eoin,
Your MATLAB install shipped with a specific JVM version. A MATLAB install is only fully supported on the JVM version it is shipped with. Check what version your MATLAB install shipped with via the following command.
version -java
MATLAB R2011b 32 bit, for example, shipped with 'Java 1.6.0_17-b04 with Sun Microsystems Inc. Java HotSpot™ Client VM mixed mode'. MATLAB R2011b shipped with 'Java 1.6.0_17-b04 with Sun Microsystems Inc. Java HotSpot™ 64-Bit Server VM mixed mode'.
From this I suggest you launch your Java application in a 32 bit runtime environment at least up to date with the MATLAB bundled software if you have MATLAB R2011b 32 bit installed and a 64 bit runtime environment if you have MATLAB R2011b 64 bit.
I would guess that at the time of writing this you were on a MATLAB 64 bit install, your 1.6 JDK was 32 bit, and your 1.7 JDK was 64 bit. I hope this shows the mismatch in your setup. I am not saying this is the only setup that will work, but it is at least a functional starting point.
Cheers, Kyle
  1 Comment
Eoin
Eoin on 25 Mar 2012
Thanks Kyle,
It looks like it's a 32bit 64bit compatibility issue alright. Thanks for your help. I'll get them all going on 1.6 64 bit.

Sign in to comment.

More Answers (1)

Kyle White
Kyle White on 26 Mar 2012
Edited: Walter Roberson on 7 Aug 2015
Hi Eoin,
I did some additional work to search for the cause of your incompatibility issue, rather than only give a possibly inflexible solution that simply says make sure everything matches up.
The MATLAB Builder JA produces JAR files that depend on javabuilder.jar. When a class contained in javabuilder.jar is instantiated for the first time, a series of things occur. Your issue occurred in the second step.
  1. Dependent classes in javabuilder.jar are loaded
  2. Static initialization of dependent classes triggers loading of a series of shared libraries in the MATLAB Compiler Runtime (MCR), which is found via the runtime file mclmcrrt7_16.dll ...
Why 32 vs 64 bit MATLAB install matters: There are two differences between these installs relevant to this issue. For a 32 bit MATLAB install, a folder with a 32 bit compiled mclmcrrt7_16.dll is placed in folder in <32bitmatlabroot>/R2011b/runtime/win32, and a 32 bit compiled version of javabuilder.jar is placed in <32bitmatlabroot>/R2011b/toolbox/javabuilder/jar. For a 64 bit MATLAB install, a folder with a 64 bit compiled mclmcrrt7_16.dll is placed in folder in <64bitmatlabroot>/R2011b/runtime/win64, and a 64 bit compiled version of javabuilder.jar is placed in <64bitmatlabroot>/R2011b/toolbox/javabuilder/jar.
Why 32 bit versus 64 bit Java compilation matters: It doesn't as far as I know. However, it may be the case that paths are set differently inside the 32 bit javabuilder.jar and the 64 bit javabuilder.jar. They are not byte identical and I did not investigate further as the issue doesn't seem to reside here.
Why 32 bit versus 64 bit java application launcher matters: When your Java application instantiates a class in javabuilder.jar, and in my experiments it didn't matter whether I called the 32 bit or 64 bit javabuilder.jar files in any scenario (and this seems to make sense given the point above), then depending on whether the JVM the code is running in is either 32 bit or 64 bit will cause javabuilder.jar to make a decision to either look for a 32 bit mclmcrrt7_16.dll or a 64 bit mclmcrrt7_16.dll in your PATH environment variable, respectively. For example, if you installed MATLAB 32 bit and try to run your application with the Java 1.7 64 bit java command then then javabuilder.jar in your classpath will look in your PATH environment variable for a 64 bit mclmcrrt7_16.dll. The 32 bit mclmcrrt7_16.dll is not considered a suitable choice and even if that is in your classpath you will receive a 'java.lang.UnsatisfiedLinkError: Failed to find library mclmcrrt7_16.dll'. Unlike the Java javabuilder.jar files, whether the C/C++ files in mclmcrrt7_16.dll have been compiled via 32 bit or 64 bit compilation matters. The same would go for installing MATLAB 64 bit, thus putting <64bitmatlabroot>/R2011b/runtime/win64 in your PATH environment variable automatically during the install, and trying to run an application with your generated Java code via the Java 1.6 32 bit command java. A class in javabuilder.jar would then try to look for a 32 bit compiled mclmcrrt7_16.dll and only find a 64 bit version, which it would not find suitable and throw a java.lang.UnsatisfiedLinkError.
What do you need to do to ensure compatibility? If you try running your Java application with Java 1.X 32 bit then ensure a 32 bit compiled mclmcrrt7_16.dll is available via your PATH environment variable (normally under a folder named 'win32'). If you try running your Java application with Java 1.X 64 bit then ensure a 64 bit compiled mclmcrrt7_16.dll is available via your PATH environment variable (normally under a folder named 'win64'). The mclmcrrt7_16.dll file is placed when you install MATLAB on your development machine or the MCR on a target deployment machine. Though it made no difference in my experiments, I would also suggest you place in your classpath when calling the java command the javabuilder.jar under <xxbitmatlabroot>/R2011b/toolbox/javabuilder/jar/win32 when you run with Java 1.X 32 bit java command and <xxbitmatlabroot>/R2011b/toolbox/javabuilder/jar/win64 when you run with Java 1.X 64 bit java command. Both of these javabuilder.jar files are included in the 32 bit and 64 bit MATLAB installs.
Sorry for the novel, but I hope this sheds some light on what was causing your error. I recreated it in a variety of ways and ran experiments to check all my conclucions. If there are errors in my reasoning, please let me know!
Cheers,
Kyle
  1 Comment
Eoin
Eoin on 27 Mar 2012
wow, Kyle. Thanks so much for this. I have tried this with my java application in 64 bit and it links across fine now.
Thanks so much for the help,
Eoin

Sign in to comment.

Categories

Find more on Java Package Integration in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!