# Trying to debug embedding of Julia in a JUCE (VST) audio plugin

**URL:** <https://discourse.julialang.org/t/trying-to-debug-embedding-of-julia-in-a-juce-vst-audio-plugin/58968>\
**Category:** General Usage\
**Tags:** embedding\
**Created:** [April 10, 2021, 8:04am UTC](https://discourse.julialang.org/t/trying-to-debug-embedding-of-julia-in-a-juce-vst-audio-plugin/58968 "2021-04-10T08:04:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![toivo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/toivo/32/50_2.png) [@toivo](https://discourse.julialang.org/u/toivo)\
**Post date:** [April 10, 2021, 8:04am UTC](https://discourse.julialang.org/t/trying-to-debug-embedding-of-julia-in-a-juce-vst-audio-plugin/58968/1 "2021-04-10T08:04:02Z")

</div>

Hi! I’m trying to embed Julia into a VST plugin (using the JUCE framework) on windows.  
JUCE provides several build targets, and the standalone target works fine (after some tweaks related to embedding Julia on windows). (I was able to generate some waveforms in real time using Julia - really nice!)

But when I try to use the actual VST3 plugin target, which creates a dll, I get a null pointer access somewhere inside `libjulia-internal.dll` when loading the plugin. I was able to debug this far:

- The call to `jl_init()` succeeds.
- Then I call `jl_eval_string("IdDict()")`, and somewhere inside that call I get the null pointer access.

Does anyone have any tips on how I can debug this? Is there a version of `libjulia-internal.dll` with debug symbols availble somewhere? Then I could at least figure out where the null pointer access occurs.

I should mention that in order to get the embedding to work, I had to go against [Embedding Julia · The Julia Language](https://docs.julialang.org/en/v1/manual/embedding/) and not link with `libopenlibm.dll.a` - otherwise I got an error that the entry point for `acos` could not be found when starting the program.

Any ideas?  
/ Toivo

---

<div class="post-metadata">

**Author:** ![toivo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/toivo/32/50_2.png) [@toivo](https://discourse.julialang.org/u/toivo)\
**Post date:** [April 10, 2021, 8:11am UTC](https://discourse.julialang.org/t/trying-to-debug-embedding-of-julia-in-a-juce-vst-audio-plugin/58968/2 "2021-04-10T08:11:24Z")

</div>

I should add that I’m using Julia 1.6.0 and Visual Studio 2017.

---

<div class="post-metadata">

**Author:** ![toivo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/toivo/32/50_2.png) [@toivo](https://discourse.julialang.org/u/toivo)\
**Post date:** [April 17, 2021, 5:45pm UTC](https://discourse.julialang.org/t/trying-to-debug-embedding-of-julia-in-a-juce-vst-audio-plugin/58968/3 "2021-04-17T17:45:10Z")

</div>

I think I figured it out.  
My plugin was creating a thread to run Julia in. Apparently, the plugin got created, destroyed, and created again, so `jl_init()` got called once from one thread, then once from another, which I don’t think is supported. I’ll have to keep one global Julia thread for the whole lifetime of the plugin.

If someone else needs to debug into e g `libjulia-internal-debug.dll` using Visual Studio, here’s a few things that I found out that might be helpful:

Building Julia from source for windows (including the debug build) was pretty easy, but that in itself didn’t help me to get debug symbols for `libjulia.dll` / `libjulia-internal.dll` that I could use with Visual Studio, because the debug symbols are in DWARF format but Visual Studio wants pdb format.

But I found a tool called [cv2pdb](https://github.com/rainers/cv2pdb) which actually worked pretty well. E g

```
cv2pdb.exe -C libjulia-internal-debug.dll

```

which creates `libjulia-internal-debug.pdb` and updates `libjulia-internal-debug.dll`. Then you put both files on your path. (This might also work on `libjulia-internal.dll` that comes in the official download, if it hasn’t been stripped.)

But the paths to the source files linked in the `.pdb` were wrong, maybe that’s why I could step into e g `jl_init()` initially. To make it work in Visual Studio, I had to

- put a breakpoint at e g `jl_init()` and run to that point in the debugger,
- go to the disassembly view and step into a few layers of calls,
  - then Visual Studio would ask me to locate the source file on disk that I had stepped into,

- open the same source file with Visual Studio,

and then I could step through the code in `libjulia-internal-debug.dll`.
