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

Add path workaround for Linux #233

Merged
merged 2 commits into from
Feb 10, 2025
Merged

Conversation

egavazzi
Copy link
Contributor

@egavazzi egavazzi commented Feb 9, 2025

Description

Exactly the same as #226, but for Linux. Tested and found out that it works too.

Related to:

Before

julia> mat"version"

[1135198] signal 11 (1): Segmentation fault
in expression starting at REPL[3]:1
Allocations: 8630736 (Pool: 8629112; Big: 1624); GC: 9
Segmentation fault (core dumped)

After

julia> mat"version"
"24.2.0.2806996 (R2024b) Update 3"

@tqml
Copy link
Collaborator

tqml commented Feb 10, 2025

I don't have a linux machine with Matlab to test it, but isn't Linux using a : instead of ; to separate elements in PATH?

Linux uses `:` as path separator, not `;` like Windows.
@egavazzi
Copy link
Contributor Author

Uh-oh, you're completely right. It was working in my minimal example to start Matlab as matlab_libpath was added at the beginning of PATH. But due to the wrong separator, the rest was not interpreted as part of PATH anymore. It should be fixed now.

@tqml tqml merged commit 3211326 into JuliaInterop:master Feb 10, 2025
3 checks passed
@tqml
Copy link
Collaborator

tqml commented Feb 10, 2025

Nice, thanks for the patch! :)

@egavazzi
Copy link
Contributor Author

Thank you for the quick review, and for catching my mistake! :)

@egavazzi egavazzi deleted the fix-segfault-linux branch February 10, 2025 12:56
@musm
Copy link
Collaborator

musm commented Feb 10, 2025

Please use rebase and merge next time.

@sdamera95
Copy link

Hello,

Thank you for the quick review, and for catching my mistake! :)

Sorry, the issue still seems to persist on Linux (Ubuntu 22.04) and Matlab 24.2.0.2712019 (R2024b) after the path workaround.

Tested with clean Julia environments across 1.9, 1.10_lts and 1.11 versions.

Also checked the pre--workaround tagged release version of MATLAB.jl(0.8.4) and by building the latest version (0.9.0) of the package locally. The issue seems to persist.

Am I missing something? Please see the error from one of the configs I tested below (all other combinations seem to be identical):

julia> versioninfo()
Julia Version 1.11.3
Commit d63adeda50d (2025-01-21 19:42 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 32 × AMD Ryzen 9 7950X 16-Core Processor
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, znver4)
Threads: 1 default, 0 interactive, 1 GC (on 32 virtual cores)
Environment:
  LD_LIBRARY_PATH = /usr/lib/x86_64-linux-gnu/gazebo-11/plugins:/opt/ros/humble/opt/rviz_ogre_vendor/lib:/opt/ros/humble/lib/x86_64-linux-gnu:/opt/ros/humble/opt/libphidget22/lib:/opt/ros/humble/lib

(test) pkg> st
Status `~/test/Project.toml`
  [10e44e05] MATLAB v0.8.4

julia> using MATLAB

julia> mat"version"

[938007] signal 11 (1): Segmentation fault
in expression starting at REPL[5]:1
Allocations: 12741729 (Pool: 12740021; Big: 1708); GC: 23
Segmentation fault (core dumped)

Could you please let me know if I am doing something wrong? I'd be happy to provide more info/ test the changes.
Thank you.

@tqml
Copy link
Collaborator

tqml commented Feb 19, 2025

Hey @sdamera95
thanks for the message. Can you show the output of MATLAB.matlab_libpath ?
Also could you try removing the LD_LIBRARY_PATH env variable?

@egavazzi
Copy link
Contributor Author

egavazzi commented Feb 19, 2025

I think I managed to reproduce the issue and fix it.

On a fresh install, I created two environments. In the first one I installed MATLAB.jl v0.8.4 and in the second one MATLAB.jl v0.9.0 (master branch from github). I installed v0.8.4 before v0.9.0. I got a segfault with both.

I fixed it by rebuilding the package (in the environment with MATLAB.jl v0.9.0) with

pkg> build MATLAB

Then restarted Julia, and it worked.

@egavazzi
Copy link
Contributor Author

egavazzi commented Feb 19, 2025

To be honest my first attempt at debugging this was: Installed MATLAB.jl v0.8.4, got a segfault. Removed MATLAB.jl v0.8.4 and installed v0.9.0 instead, got a segfault. Nuked .julia/compiled/v.11/MATLAB/ and .julia/packages/MATLAB/, retried with v0.9.0 and it worked.

Then I remembered that to change matlab version one has to trigger a rebuild with pkg> build MATLAB. So I did what is described in my previous comment, which is more elegant than manually removing things under compiled/ and packages/. However if rebuilding does not work you might want to try the manual removing solution.

@egavazzi
Copy link
Contributor Author

Fun (and somewhat interesting) fact: after rebuilding MATLAB.jl v0.9.0, the version v0.8.4 is also working. But even better, rebuilding the version 0.8.4 does not bring back the segfault. It just continues to work??

I am not competent enough to understand what is happening here. And the fact that two installations of MATLAB.jl in two different environments affect each other in the first place is also something that confuses me.

@tqml
Copy link
Collaborator

tqml commented Feb 21, 2025

That is very odd.
I know the package has a build.jl that searches for MATLAB (either via an ENV variable or in the default install locations), picks the newest version and writes the file system path to a deps.jl file. This file is then imported in the package.
Maybe the different packages reference the same deps.jl file that links to a working MATLAB installation? You can check MATLAB.matlab_libpath, this constant is defined in deps.jl

@egavazzi
Copy link
Contributor Author

In both environments (with the different versions of MATLAB.jl), I get

julia> MATLAB.matlab_libpath
"/usr/local/MATLAB/R2024b/bin/glnxa64"

The content of deps.jl in .julia/packages/MATLAB/XXX/deps/ is also the same for both:

# This file is automatically generated, do not edit.

function check_deps()
    if libmx_size != filesize(Libdl.dlpath(joinpath(matlab_libpath, "libmx")))
        error("MATLAB library has changed, re-run Pkg.build(\"MATLAB\")")
    end
end

const matlab_libpath = "/usr/local/MATLAB/R2024b/bin/glnxa64"
const matlab_cmd = "exec /usr/local/MATLAB/R2024b/bin/matlab"
const libmx_size = 3600568

I removed everything in .julia/packages/MATLAB/, reinstalled the v0.8.4 to get again the "non-working" version with the segfault. I checked again both MATLAB.matlab_libpath and the content of deps.jl but they are the same as above.

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 this pull request may close these issues.

4 participants