DynamicallyLoadedEmbedding is a package which explains how to embed Julia in an application by dynamically loading libjulia
at runtime with dlopen
(Linux, Apple) or LoadLibrary
(Windows).
Compared to “traditional” embedding, as described in the Julia manual, the main difference of this approach is that Julia is not a build dependency of the application and that the application can be used with whatever Julia 1.x version the user happens to have installed, or without Julia installed or bundled at all if the user does not need the functionality provided by the Julia embedding.
Another side of this approach is that all interaction between the application and the Julia code is done through cfunction
s. This somewhat limits what you can express in the embedding but drastically simplifies working with it.
The main drawback is that the initialization is more complex because of the dynamic loading of libjulia
. This is handled by the sample C code in the package and large parts of it can be reused.
Final note: Don’t bother with using DynamicallyLoadedEmbedding
. There’s literally nothing in there. The entire value is in the sample C embedding, the documentation, and the code to test the embedding. Pkg.test("DynamicallyLoadedEmbedding")
is a meaningful thing to do and provides an easy way to test new versions of Julia with this approach to embedding.