# Is it possible for "ccall" to call the shared library created by PackageCompiler.jl?

**URL:** https://discourse.julialang.org/t/is-it-possible-for-ccall-to-call-the-shared-library-created-by-packagecompiler-jl/84298
**Category:** General Usage
**Tags:** ccall, package-compiler
**Created:** [July 16, 2022, 3:14am UTC](https://discourse.julialang.org/t/is-it-possible-for-ccall-to-call-the-shared-library-created-by-packagecompiler-jl/84298 "2022-07-16T03:14:08Z")
**Posts on this page:** 1
**Showing post:** 48

<div class="post-metadata">

### Author: ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)
#### Post date: [July 25, 2022, 12:55am UTC](https://discourse.julialang.org/t/is-it-possible-for-ccall-to-call-the-shared-library-created-by-packagecompiler-jl/84298/48 "2022-07-25T00:55:04Z")

</div>

> [@ohmsweetohm1](#):
>
> is an issue of Julia and not Matlab.

It is a Julia issue. The embedding mechanism is not designed for multiple embeddings. Running the atexit hooks is meant to do things such as flushing buffers or unlocking files. It is not necessarily tearing down and explicitly freeing every structure.

I’m not sure why it should be possible to repeatedly shutdown and initialize Julia within the same process. Java is another example where this restarting the runtime is not supported.

I suppose if you really wanted to do this, you could start a MATLAB worker and call this just before you terminate the worker. Another option would be to do the embedding via a mex file and call this during mexAtExit:

> **[Register function to call when MEX function clears or MATLAB terminates - MATLAB](https://www.mathworks.com/help/matlab/apiref/mexatexit.html)**
>
> Use mexAtExit to register a function to call just before clearing the MEX function or terminating MATLAB.

There might still have a similar issue if you try to reload the mex file.

I will refer you to @Sukera’s post in another thread.

> [@Initialize the julia runtime more than once within C++](https://discourse.julialang.org/t/initialize-the-julia-runtime-more-than-once-within-c/82892/2):
>
> You only need to initialize the runtime once - it’s supposed to be kept around between function invocations. I suggest you do that outside of your request calling logic, since calling jl\_init more than once effectively means running julia multiple times at the same time (in the same process - which will break).

---

_[View the full topic](https://discourse.julialang.org/t/is-it-possible-for-ccall-to-call-the-shared-library-created-by-packagecompiler-jl/84298)._
