Closed crisluengo closed 4 months ago
[This post documents my path to understanding and solving this issue. Consequently, it contains some information that turned out not be relevant to this issue. I wanted to leave it in for future reference.]
Many places suggest setting either java.io.tmpdir
or jna.tmpdir
to a different directory. It seems that JNA unpacks a shared object to this directory, so it must be possible to execute programs in the chosen temp directory.
You can set Java variables in MATLAB by creating a file java.opts
in your MATLAB startup directory, containing the line -Djava.io.tmpdir=/Users/cris/tmp
(or whatever directory you want to use).
This has not fixed the issue for me.
Here it is suggested that JNA 5.5.0 and earlier are not compatible with Big Sur (macOS 11) and later. Upgrading JNA would solve this issue.
I've found JNA's temporary shared object file ~/tmp/jna-3062233/jna12427569927680089380.tmp
.
cris@paella:~/src/diplib> lipo -info ~/tmp/jna-3062233/jna12427569927680089380.tmp
Architectures in the fat file: /Users/cris/tmp/jna-3062233/jna12427569927680089380.tmp are: i386 x86_64 ppc7400
...meaning that the JNA we've got here is not built for arm64. The Java VM I've got is arm64. This is the reason this will not work. Updating JNA is definitely the way to go.
When we build Viewer.java
, we link JNA, JOGL and GlueGen from the MATLAB directory. But the JNA JAR file that comes with MATLAB doesn't work on Apple Silicon macOS (arm64), it's a really old version.
So, I guess we need to supply a custom installation of these Java packages for Apple Silicon users. I'm waiting on an answer to this question, maybe there's a neater way to solve this. I'll update the solution below if so.
Download the latest JNA JAR file, for example from maven.org. Currently it's this one: https://repo1.maven.org/maven2/net/java/dev/jna/jna/5.14.0/jna-5.14.0.jar
In ${matlabroot}/java/jarext/svnkit
you'll find a file jna.jar
. Overwrite it with the one you just downloaded (or rename this one). Make sure the new file gets the same name as the old one, you'll need to rename it to remove the version number.
[${matlabroot}
can be found by typing matlabroot
at the MATLAB command prompt.]
Restart MATLAB. viewslice
should now work.
NOTE: I have no idea what this could break, but considering that the old jna.jar
does not work on Apple Silicon, nothing will break that wasn't already broken.
The problem with the jna.jar
file that comes with MATLAB is that it contains an embedded binary built for architectures i386, x86_64 and ppc7400, but not for arm64, which is the Apple Silicon architecture. Note that i386 and ppc7400 have not been supported by Apple for a really long time, so this is a really old version of JNA!
viewslice
doesn't work for me any more, I get the following error message:I'm running MATLAB R2023b on a M1 Mac with macOS Sonoma. This version of MATLAB uses Amazon Coretto 8, installed separately according to the installation instructions for Apple Silicon machines.
JNA is available. I also updated to the latest release of Coretto 8, then told MATLAB to use Coretto 11, then recompiled Viewer.jar using Coretto 11 instead of the system-default JDK, none of those fixed it.
It might be some configuration issue, but I don't know where to even start looking for those. Googling for the error message leads to comments about executables in the temporary directory, but I couldn't figure out how to configure that for MATLAB.