Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail to build the MATLAB due to the load error of libmx #205

Closed
jxpeng98 opened this issue Sep 28, 2022 · 9 comments · Fixed by #212
Closed

Fail to build the MATLAB due to the load error of libmx #205

jxpeng98 opened this issue Sep 28, 2022 · 9 comments · Fixed by #212

Comments

@jxpeng98
Copy link

jxpeng98 commented Sep 28, 2022

Hi,

Many thanks for this excellent package. I tried to add this pkg and build it, but I failed.

Here is the error report.

    Building MATLAB → `~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/e263657fe013cb02450c5d4210d2c50a354a5e08/build.log`
ERROR: Error building `MATLAB`:
[ Info: Detected MATLAB root folder at "/Applications/MATLAB_R2022b.app"
[ Info: Detected MATLAB library path at "/Applications/MATLAB_R2022b.app/bin/maci64"
[ Info: Detected MATLAB executable at "/Applications/MATLAB_R2022b.app/bin/matlab"
ERROR: LoadError: could not load library "/Applications/MATLAB_R2022b.app/bin/maci64/libmx"
dlopen(/Applications/MATLAB_R2022b.app/bin/maci64/libmx.dylib, 0x0001): tried: '/Applications/MATLAB_R2022b.app/bin/maci64/libmx.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Applications/MATLAB_R2022b.app/bin/maci64/libmx.dylib' (no such file), '/Applications/MATLAB_R2022b.app/bin/maci64/libmx.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))
Stacktrace:
 [1] dlopen(s::String, flags::UInt32; throw_error::Bool)
   @ Base.Libc.Libdl ./libdl.jl:117
 [2] dlopen (repeats 2 times)
   @ ./libdl.jl:116 [inlined]
 [3] dlpath(libname::String)
   @ Base.Libc.Libdl ./libdl.jl:240
 [4] top-level scope
   @ ~/.julia/packages/MATLAB/SVjnA/deps/build.jl:79
 [5] include(fname::String)
   @ Base.MainInclude ./client.jl:476
 [6] top-level scope
   @ none:5
in expression starting at /Users/pengjiaxin/.julia/packages/MATLAB/SVjnA/deps/build.jl:76

The Julia and system details:

Commit afb6c60d69a (2022-09-06 15:09 UTC)
Platform Info:
  OS: macOS 13 (arm64-apple-darwin21.5.0)
  CPU: 10 × Apple M1 Max
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, apple-m1)
  Threads: 1 on 8 virtual cores
Environment:
  LD_LIBRARY_PATH = :/Applications/MATLAB_R2022b.app/bin/glnxa64
@dominicblanco
Copy link

dominicblanco commented Nov 30, 2022

I am having this same problem. Were you able to find a solution?

One issue is that you are using R2022a, which will yield an issue, but even when I changed ENV["MATLAB_ROOT"] = /Applications/MATLAB_R2021b.app the error persisted.

@dominicblanco
Copy link

Adding to this:
On my Windows computer, I had no issues using this package. This is a Mac-only issue.

@dominicblanco
Copy link

Another update: It seems this is a more serious issue than expected. On the forum, people believe it is an issue with macOS. It seems that somehow, MATLAB.jl has become incompatible with certain versions of macOS. This is a more serious issue.

@jxpeng98
Copy link
Author

Another update: It seems this is a more serious issue than expected. On the forum, people believe it is an issue with macOS. It seems that somehow, MATLAB.jl has become incompatible with certain versions of macOS. This is a more serious issue.

Hi, thanks for your sharing.

Recently, I tested Julia with the new MATLAB R2022b native apple silicon version.

First change the environment with your code ENV["MATLAB_ROOT"] = "/Applications/MATLAB_R2022b_Beta.app"

The output is:

Building MATLAB → `~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/e263657fe013cb02450c5d4210d2c50a354a5e08/build.log`
ERROR: Error building `MATLAB`:
[ Info: Detected MATLAB root folder at "/Applications/MATLAB_R2022b_Beta.app"
[ Info: Detected MATLAB executable at "/Applications/MATLAB_R2022b_Beta.app/bin/matlab"
ERROR: LoadError: could not load library "/Applications/MATLAB_R2022b_Beta.app/bin/maci64/libmx"
dlopen(/Applications/MATLAB_R2022b_Beta.app/bin/maci64/libmx.dylib, 0x0001): tried: '/Applications/MATLAB_R2022b_Beta.app/bin/maci64/libmx.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Applications/MATLAB_R2022b_Beta.app/bin/maci64/libmx.dylib' (no such file), '/Applications/MATLAB_R2022b_Beta.app/bin/maci64/libmx.dylib' (no such file)
Stacktrace:
 [1] dlopen(s::String, flags::UInt32; throw_error::Bool)
   @ Base.Libc.Libdl ./libdl.jl:117
 [2] dlopen (repeats 2 times)
   @ ./libdl.jl:116 [inlined]
 [3] dlpath(libname::String)
   @ Base.Libc.Libdl ./libdl.jl:240
 [4] top-level scope
   @ ~/.julia/packages/MATLAB/SVjnA/deps/build.jl:79
 [5] include(fname::String)
   @ Base.MainInclude ./client.jl:476
 [6] top-level scope
   @ none:5

From the repo of MATLAB.jl, they mentioned that

MATLAB versions 2022a/2022b trigger a segfault and no not work with MATLAB.jl. Maintainers are attempting to diagnoise the cause and fix the issue.**

I think the problem is the conflict between MATLAB (Rosetta version) and Julia (Native version). You may solve the problem by installing both MATLAB and Julia under x86 platform via Rosetta. Or maybe wait for the update of the package.

@pitsianis
Copy link
Contributor

I am getting the same error as @jxpeng98 with prerelease MATLAB R2023b aa64 native and julia 1.9.1 native on macOS 13.4.1

The last line missing from the above output is

in expression starting at /Users/userid/.julia/packages/MATLAB/SVjnA/deps/build.jl:76

I appreciate your hard work in releasing MATLAB.jl. Let us know how we can help.

@pitsianis
Copy link
Contributor

This error is because the build.jl is looking for libmx at directory maci64 which does not exist in aa64 Macs.

So I replaced deps/build.jl:53 from

       Sys.WORD_SIZE == 32 ? "maci" : "maci64"

to

       archchar = Sys.ARCH == :aarch64 ? "a" : "i"
       Sys.WORD_SIZE == 32 ? "maci" : "mac" * archchar * "64"

Now MATLAB.jl builds! However

julia> using MATLAB

julia> mat"1 + 1"
env: /Applications/MATLAB_R2023b.app/bin/maci64/path_per_install: No such file or directory
mkdir: /bin/maci64: Operation not permitted
ERROR: MATLAB.MEngineError("failed to open MATLAB engine session")
Stacktrace:
 [1] MSession(bufsize::Int64; flags::String)
   @ MATLAB ~/projects/MATLAB.jl/src/engine.jl:34
 [2] MSession (repeats 2 times)
   @ ~/projects/MATLAB.jl/src/engine.jl:22 [inlined]
 [3] get_default_msession
   @ ~/projects/MATLAB.jl/src/engine.jl:88 [inlined]
 [4] eval_string(stmt::String)
   @ MATLAB ~/projects/MATLAB.jl/src/engine.jl:147
 [5] top-level scope
   @ ~/projects/MATLAB.jl/src/matstr.jl:161

I get the same error when starting MATLAB from the terminal command line. Would someone else be able to give it a try and tell me what happens?

@pitsianis
Copy link
Contributor

The above change fixes it and runs correctly. I have placed a pull request.

@vardister
Copy link

The above change fixes it and runs correctly. I have placed a pull request.

Can confirm that this fixes the issue for macos using the latest MATLAB R2023b pre-reslease version (native ARM)!

@musm musm closed this as completed in #212 Jul 12, 2023
@musm
Copy link
Collaborator

musm commented Jul 12, 2023

sorry about the late fix merge. New tag version is in the works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants