JuliaInterop / MATLAB.jl

Calling MATLAB in Julia through MATLAB Engine
MIT License
270 stars 63 forks source link

UndefRefError in MAC OS Apple Silicon #195

Open jinzhaohu opened 2 years ago

jinzhaohu commented 2 years ago

Hi:

When I try to use this package, it keeps reminding me UndefRefError.

I have set ENV["MATLAB_HOME"]="/Applications/MATLAB_R2021b.app" in Julia and build MATLAB, but it didn't work.

Do you have any idea on how fix it?

THX!!

GrantHecht commented 2 years ago

I've run into this same issue as well. I expect it's due to running the native Apple Silicon version of Julia while attempting to use MATLAB which only currenrly supports x86 with Rosetta. Please note that I'm far from an expert on this topic so I may be compleately incorrect about this

I've gotten arround this issue by continuing to use Julia's x86 release for Mac when I need MATLAB interoperability.

musm commented 2 years ago

@GrantHecht are you also seeing the same problems as OP?

GrantHecht commented 2 years ago

@musm, I believe so. Here's a simple MWE with stack trace:

using MATLAB

mat"""
a = 1 + 2;
"""

ERROR: UndefRefError: access to undefined reference
Stacktrace:
 [1] MSession(bufsize::Int64; flags::String)
   @ MATLAB ~/.julia/packages/MATLAB/T20Ly/src/engine.jl:26
 [2] MSession (repeats 2 times)
   @ ~/.julia/packages/MATLAB/T20Ly/src/engine.jl:23 [inlined]
 [3] get_default_msession
   @ ~/.julia/packages/MATLAB/T20Ly/src/engine.jl:88 [inlined]
 [4] eval_string(stmt::String)
   @ MATLAB ~/.julia/packages/MATLAB/T20Ly/src/engine.jl:147
 [5] top-level scope
   @ ~/.julia/packages/MATLAB/T20Ly/src/matstr.jl:161

Note that this only occurs when using the ARM Julia release. I don't have any issues on my M1 Mac when using the x86 release through Rosetta.