Has anyone had success using Julia from Matlab?

Hum, interesting. When compiling using the usual way (-ljulia and without dlopen), MATLAB always crashed with the error:

fatal: error thrown and no exception handler available.
InitError(mod=:Sys, error=ErrorException("could not load symbol "jl_cpu_threads":

Hence, since it seems I need the dlopen for some reason, I will try to do what you said about initialize Julia once per MATLAB session and access the functions by dlsym.

Thanks!

Oh right. So I don’t quite understand what’s going on here, but it looks like a problem with symbol lookup where the JIT compiled Sys.__init__() can’t find jl_cpu_threads from libjulia. Presumably this could be related to the flags matlab uses when it dlopens your mex file. So to repro outside of matlab you could try a simple executable which dlopens a shared library using RTLD_LOCAL and tries to call a function from it. In turn that function would try to call a function from libjulia? I’m not sure that makes sense though because I’m not sure how the linker handles symbol scope for chained library dependencies.

1 Like

If that’s the case, this discussion seems to be relevant,

2 Likes

Yes, that looks very related. Using dlopen seems like a kinda nasty workaround but it might be necessary for now. Could be worth reporting as an issue if a minimal example can be found. I’m not sure whether this is julia’s fault or a limitation of the system dynamic linker.

2 Likes

Hi, following on from my previous comment I have a working version that allows me to call Julia 1.0.3 functions with MATLAB (using PyCall).

https://github.com/Timmmdavis/MATLABToJuliaViaPythonAndBackAgain…

Comments appreciated.
Also interested to hear if it works on Linux,

2 Likes