JuliaInterop / MATLAB.jl

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

Add Path workaround for windows #226

Closed bolognam closed 1 month ago

bolognam commented 1 month ago

See issue #200 for more details, specifically:

inkydragon commented 1 month ago

Another choice is to modify the environment variables using withenv only when dlopen is called.

https://github.com/JuliaInterop/MATLAB.jl/blob/f8673970d1fb9144a058b37c28fd827ea4f34fbd/src/MATLAB.jl#L84-L86

topolarity commented 1 month ago

That would have to wrap around every function call, because they can dynamically trigger additional LoadLibrary calls internally (which is exactly what engOpen does - the dlopen actually succeeds)

musm commented 1 month ago

I wonder if there is a less invasive approach as a bulk modification of the environment variable, as I think has the potential to corrupt other libraries.

topolarity commented 1 month ago

I believe that AddDllDirectory would be the primary alternative (https://github.com/jheinen/GR.jl/issues/489 seemed to tread similar ground)

However, those directories won't be seen by a LoadLibraryW w/o flags like the one in MATLAB, which doesn't opt-in to the new search directories.

SetDefaultDllDir does change the LoadLibraryW behavior to use the added paths, but it's broken for e.g. SuiteSparse in Julia unless changes are made to Julia's library loading behavior: https://github.com/JuliaLang/julia/pull/47775

musm commented 1 month ago

@topolarity I think we should explore that option in another PR. For now I will merge this since it at least allows us to use MATLAB. @bolognam do you mind also updating the readme?