# Has anyone had success using Julia from Matlab?

**URL:** https://discourse.julialang.org/t/has-anyone-had-success-using-julia-from-matlab/16661
**Category:** General Usage
**Created:** [October 23, 2018, 1:07am UTC](https://discourse.julialang.org/t/has-anyone-had-success-using-julia-from-matlab/16661 "2018-10-23T01:07:39Z")
**Posts on this page:** 5
**Page:** 2

<div class="post-metadata">

### Author: ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)
#### Post date: [December 24, 2018, 11:41am UTC](https://discourse.julialang.org/t/has-anyone-had-success-using-julia-from-matlab/16661/21 "2018-12-24T11:41:15Z")

</div>

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

```julia
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!

---

<div class="post-metadata">

### Author: ![c42f](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/c42f/32/52842_2.png) [@c42f](https://discourse.julialang.org/u/c42f)
#### Post date: [December 26, 2018, 1:11am UTC](https://discourse.julialang.org/t/has-anyone-had-success-using-julia-from-matlab/16661/22 "2018-12-26T01:11:41Z")

</div>

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 `dlopen`s your mex file. So to repro outside of matlab you could try a simple executable which `dlopen`s 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.

---

<div class="post-metadata">

### Author: ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)
#### Post date: [December 26, 2018, 1:51am UTC](https://discourse.julialang.org/t/has-anyone-had-success-using-julia-from-matlab/16661/23 "2018-12-26T01:51:38Z")

</div>

> [@c42f](#):
>
> Presumably this could be related to the flags matlab uses when it `dlopen` s your mex file.

If that’s the case, [this discussion](https://discourse.julialang.org/t/different-behaviours-in-linux-and-macos-with-julia-embedded-in-c/18101) seems to be relevant,

---

<div class="post-metadata">

### Author: ![c42f](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/c42f/32/52842_2.png) [@c42f](https://discourse.julialang.org/u/c42f)
#### Post date: [December 26, 2018, 11:35am UTC](https://discourse.julialang.org/t/has-anyone-had-success-using-julia-from-matlab/16661/24 "2018-12-26T11:35:04Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![timmm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/timmm/32/6760_2.png) [@timmm](https://discourse.julialang.org/u/timmm)
#### Post date: [January 16, 2019, 4:11pm UTC](https://discourse.julialang.org/t/has-anyone-had-success-using-julia-from-matlab/16661/25 "2019-01-16T16:11:20Z")

</div>

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…](https://github.com/Timmmdavis/MATLABToJuliaViaPythonAndBackAgain...)

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

[Previous page](https://discourse.julialang.org/t/has-anyone-had-success-using-julia-from-matlab/16661.md?page=1)
