# Embedding Julia in C

**URL:** <https://discourse.julialang.org/t/embedding-julia-in-c/23931>\
**Category:** New to Julia\
**Created:** [May 6, 2019, 8:16pm UTC](https://discourse.julialang.org/t/embedding-julia-in-c/23931 "2019-05-06T20:16:45Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josiah\_Slack](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josiah_slack/32/8319_2.png) [@Josiah\_Slack](https://discourse.julialang.org/u/Josiah_Slack)\
**Post date:** [May 6, 2019, 8:16pm UTC](https://discourse.julialang.org/t/embedding-julia-in-c/23931/1 "2019-05-06T20:16:45Z")

</div>

I recently created a topic called “Calling my own Julia module from C”, asking a nuts and bolts question about a use case that wasn’t covered by the documentation. I haven’t given up hope on getting an answer, but I thought it might be worthwhile to ask a more general question.

Is calling Julia from C an extremely unusual use case?

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [May 6, 2019, 9:37pm UTC](https://discourse.julialang.org/t/embedding-julia-in-c/23931/2 "2019-05-06T21:37:53Z")

</div>

It’s not the most common thing to do, but it is certainly done and pretty thoroughly documented:

[https://docs.julialang.org/en/v1/manual/embedding/index.html](https://docs.julialang.org/en/v1/manual/embedding/index.html)

Was there anything specific you wanted to know that’s not documented in there?

---

<div class="post-metadata">

**Author:** ![Pbellive](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pbellive/32/3604_2.png) [@Pbellive](https://discourse.julialang.org/u/Pbellive)\
**Post date:** [May 6, 2019, 9:50pm UTC](https://discourse.julialang.org/t/embedding-julia-in-c/23931/3 "2019-05-06T21:50:56Z")

</div>

I replied to your "Calling my own Julia module from C question. Linking here for reference:

> [@Calling my own Julia module from C](https://discourse.julialang.org/t/calling-my-own-julia-module-from-c/23779/2):
>
> I don’t have too much experience with this but I’ve gotten it to work. I found [this thread](https://discourse.julialang.org/t/calling-jl-gc-push1-multiple-times/18666) very helpful. The thread is about dealing with garbage collection when calling julia from C but the first post has a good example of loading a module from C (C++ actually but I think everything there works in C) and then calling a function from that module. I’ve used that approach to call my own modules from C. As far as I can tell loading modules is not in the embedding documentation though so I’m not su…

---

<div class="post-metadata">

**Author:** ![Josiah\_Slack](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josiah_slack/32/8319_2.png) [@Josiah\_Slack](https://discourse.julialang.org/u/Josiah_Slack)\
**Post date:** [May 6, 2019, 11:21pm UTC](https://discourse.julialang.org/t/embedding-julia-in-c/23931/4 "2019-05-06T23:21:43Z")

</div>

What I’m interested in doing is calling functions that aren’t defined in Base, which, as far as I can tell, the documentation doesn’t touch on.

---

<div class="post-metadata">

**Author:** ![Josiah\_Slack](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josiah_slack/32/8319_2.png) [@Josiah\_Slack](https://discourse.julialang.org/u/Josiah_Slack)\
**Post date:** [May 6, 2019, 11:23pm UTC](https://discourse.julialang.org/t/embedding-julia-in-c/23931/5 "2019-05-06T23:23:27Z")

</div>

Good idea linking to my other post; I should have done it myself. Thanks again for the lead.

---

<div class="post-metadata">

**Author:** ![Biao](https://avatars.discourse-cdn.com/v4/letter/b/8baadc/32.png) [@Biao](https://discourse.julialang.org/u/Biao)\
**Post date:** [April 26, 2020, 6:22am UTC](https://discourse.julialang.org/t/embedding-julia-in-c/23931/6 "2020-04-26T06:22:02Z")

</div>

Hi Josiah, could you provide the link to your other post where you have done “Embedding Julia in C” described at the beginning of this post?

---

<div class="post-metadata">

**Author:** ![Josiah\_Slack](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josiah_slack/32/8319_2.png) [@Josiah\_Slack](https://discourse.julialang.org/u/Josiah_Slack)\
**Post date:** [April 26, 2020, 2:02pm UTC](https://discourse.julialang.org/t/embedding-julia-in-c/23931/7 "2020-04-26T14:02:01Z")

</div>

Realized that the link was already in the thread: [https://discourse.julialang.org/t/calling-my-own-julia-module-from-c/23779](https://discourse.julialang.org/t/calling-my-own-julia-module-from-c/23779)

---

<div class="post-metadata">

**Author:** ![RoyiAvital](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/royiavital/32/571_2.png) [@RoyiAvital](https://discourse.julialang.org/u/RoyiAvital)\
**Post date:** [April 26, 2020, 3:45pm UTC](https://discourse.julialang.org/t/embedding-julia-in-c/23931/8 "2020-04-26T15:45:00Z")

</div>

> [@Josiah\_Slack](#):
>
> Is calling Julia from C an extremely unusual use case?

I think it could be one of the strongest selling point of Julia if one could easily embed his Julia functions in production code (Which for some reasons must be `C` / `C++`). Being efficient way to abstract highly optimized code for production.

I couldn’t find documentation how could one embed a whole self written function which uses different packages and even relies on, let’s say, OpenBLAS.

I also assume this method means code will behave just like regular Julia code with compilation time. While I’d be happy to have a mode which can prevent that with some assumptions.  
For instance, Image Filtering with `StaticKernels` with the kernel and image size to be constant.  
Maybe another mode with Pre Compiled Libraries attached to the code.
