# Embedding julia to extend c++ app for long developing code

**URL:** <https://discourse.julialang.org/t/embedding-julia-to-extend-c-app-for-long-developing-code/123580>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [December 8, 2024, 12:26am UTC](https://discourse.julialang.org/t/embedding-julia-to-extend-c-app-for-long-developing-code/123580 "2024-12-08T00:26:21Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sergey](https://avatars.discourse-cdn.com/v4/letter/s/9fc348/32.png) [@Sergey](https://discourse.julialang.org/u/Sergey)\
**Post date:** [December 8, 2024, 12:26am UTC](https://discourse.julialang.org/t/embedding-julia-to-extend-c-app-for-long-developing-code/123580/1 "2024-12-08T00:26:21Z")

</div>

Hi everyone!  
I face with interesting problem.  
I need a language to extend existence c++ software.

Support user functions, add optimization over calculations and possible neural network experiments with solution.

The key point on `julia` is a possibility to get c-function pointer, which could be used within existent code easly. Its really interesting!

But project should exist for many many yaers with intensively developing. (but i have issues with julia every day, python dont even have such possibilities - fast user functions)

This community differently has a lot of expirience with julia.  
Can you share your experience? Is it good with optimization and neural networking? (no tensorflow support). Is it good in long developing?

Thanks

---

<div class="post-metadata">

**Author:** ![Sergey](https://avatars.discourse-cdn.com/v4/letter/s/9fc348/32.png) [@Sergey](https://discourse.julialang.org/u/Sergey)\
**Post date:** [December 8, 2024, 12:28am UTC](https://discourse.julialang.org/t/embedding-julia-to-extend-c-app-for-long-developing-code/123580/2 "2024-12-08T00:28:40Z")

</div>

python could be fast if we fill data arrays within python (user functions defined in pyhon and executed to fill array, no calling for python api within c++ millions of times)

But julia functions could be handled as any c++ functions (with several difficulties of this functions bodies)

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [December 8, 2024, 10:32am UTC](https://discourse.julialang.org/t/embedding-julia-to-extend-c-app-for-long-developing-code/123580/3 "2024-12-08T10:32:45Z")

</div>

It’s unclear what you really want to know, but it’s indeed straightforward to call Julia from C++ using function pointers created with the `@cfunction` macro. We have done so at work for many years to call Julia from a C++ GUI application. Since the Julia parts are optional to the application, we have chosen to load libjulia dynamically, and the principal approach is documented at [GitHub - GunnarFarneback/DynamicallyLoadedEmbedding.jl: Embed Julia with dynamical loading of libjulia at runtime.](https://github.com/GunnarFarneback/DynamicallyLoadedEmbedding.jl)

---

<div class="post-metadata">

**Author:** ![terasakisatoshi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/terasakisatoshi/32/9187_2.png) [@terasakisatoshi](https://discourse.julialang.org/u/terasakisatoshi)\
**Post date:** [December 8, 2024, 10:55am UTC](https://discourse.julialang.org/t/embedding-julia-to-extend-c-app-for-long-developing-code/123580/4 "2024-12-08T10:55:16Z")

</div>

> **[GitHub - AtelierArith/embedding-julia: Call Julia from C++](https://github.com/AtelierArith/embedding-julia)**
>
> Call Julia from C++

Is this?

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [December 8, 2024, 5:24pm UTC](https://discourse.julialang.org/t/embedding-julia-to-extend-c-app-for-long-developing-code/123580/5 "2024-12-08T17:24:06Z")

</div>

[https://clemens-cords.com/jluna/](https://clemens-cords.com/jluna/)

> ### Julia C-API
> 
> The Julia C-API provides the “backbone” of Julia and is the basis for jluna and most other foreign-language libraries interacting with Julia. While powerful, the C-API can be quite hard to use and poorly documented. **jluna aims to resolve this, fully wrapping the C-API in all of the convenience of modern C++** : automatic memory management, proper exception handling and much nicer syntax. Other than this, Julia C-API and jluna are functionally equivalent.
> 
> **The one area where jluna actually has more features than the C-API is in parallelization** : jluna provides a thread pool that allows C-side functions to interact with the Julia state, **something that is not possible using only [t]he C-API**.
> 
> [Info on for calling in the other direction to C++, from Julia has more package alternatives]  
> […]
> 
> ### [CxxWrap.jl](https://github.com/JuliaInterop/CxxWrap.jl)
> 
> […]
> 
> ### [CxxInterface.jl](https://juliahub.com/ui/Packages/CxxInterface/5a4dz/1.0.1) / [CxxCall.jl](https://github.com/jw3126/CxxCall.jl)
> 
> CxxInterface.jl and CxxCall.jl both aim to call C++ functions (contained in a shared library) from Julia. They essentially are a _ccall_ for C++, not a full language wrapper, the projects are therefore not functionally equivalent. jluna [does provide a way for the julia state to call any C++ function](https://clemens-cords.com/jluna/cppcall.html), the mechanism to achieve this is completely different, however.
> 
> **In summary, the only fully functional equivalent for jluna is the Julia C-API, as only it provides a Julia-wrapper that assumes C / C++ as the host language. It is therefore the superior choice in projects where Julia plays an auxiliary rule while C++ is more dominant, as jluna provides clearer design, more documentation and overall ease-of-use when compared to the C-API.**

Like the C API of Julia, jluna supports all platforms; except the only reason I can see not using it, in preference to the C API directly, is if you require macOS support, but it’s a known issue that you can help fix:  
[https://github.com/Clemapfel/jluna/issues/64](https://github.com/Clemapfel/jluna/issues/64)

---

<div class="post-metadata">

**Author:** ![Sergey](https://avatars.discourse-cdn.com/v4/letter/s/9fc348/32.png) [@Sergey](https://discourse.julialang.org/u/Sergey)\
**Post date:** [December 8, 2024, 6:33pm UTC](https://discourse.julialang.org/t/embedding-julia-to-extend-c-app-for-long-developing-code/123580/6 "2024-12-08T18:33:05Z")

</div>

Thanks. I try to use CxxWrap for c++ to julia bindings.  
Does `jluna` support `cfunction` or such function pointer could be recieved by pure c-api?

---

<div class="post-metadata">

**Author:** ![Sergey](https://avatars.discourse-cdn.com/v4/letter/s/9fc348/32.png) [@Sergey](https://discourse.julialang.org/u/Sergey)\
**Post date:** [December 8, 2024, 6:35pm UTC](https://discourse.julialang.org/t/embedding-julia-to-extend-c-app-for-long-developing-code/123580/7 "2024-12-08T18:35:05Z")

</div>

Thanks for the link. By now i was trying to keep going with the documentation.

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [December 8, 2024, 6:35pm UTC](https://discourse.julialang.org/t/embedding-julia-to-extend-c-app-for-long-developing-code/123580/8 "2024-12-08T18:35:52Z")

</div>

jluna is the only alternative to embed Julia into C++. CxxWrap.jl is for the other way call C++ from Julia, but that’s not what you asked for, though it might also be an option for you.

---

<div class="post-metadata">

**Author:** ![Sergey](https://avatars.discourse-cdn.com/v4/letter/s/9fc348/32.png) [@Sergey](https://discourse.julialang.org/u/Sergey)\
**Post date:** [December 8, 2024, 6:40pm UTC](https://discourse.julialang.org/t/embedding-julia-to-extend-c-app-for-long-developing-code/123580/9 "2024-12-08T18:40:07Z")

</div>

dynamic loading is a way.  
is it a huge limitation?

```julia
All interaction is made via cfunctions - less powerful interface than the "regular" embedding.

```

Im trying to bind c++ structures and methods into `julia`, but c-api could be difficult with binded structure. (i dont found a way to call c\_function with c++ structures as arguments) Was it a problem for you or you manage it some other way.

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [December 8, 2024, 7:09pm UTC](https://discourse.julialang.org/t/embedding-julia-to-extend-c-app-for-long-developing-code/123580/10 "2024-12-08T19:09:50Z")

</div>

We make all calls with basic C types as arguments. It’s fully sufficient for the interactions we need.
