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

Thank you!
So i have to make the .lib, and following this guide it should be possible to statically use the dll in an app.

Another option, that is more similar to what I have done in Matlab, would be to to use dynamic linking at run-time

I followed your example code to edit my project, and it worked, but subject to the same error. I’ll appreciate it if you could share your new progress about our similar issue.

Could you be more specific? Are you encountering the error that occurs when you try to shutdown and reinitialize Julia? If so, the solution is do not shutdown Julia unless you are planning to exit the process (e.g. MATLAB).

I write code like
"
addpath(genpath(binPath), ‘-end’);
savepath;
libname = fullfile(binPath, dllName);
hfile = fullfile(inludePath, headh);
loadlibrary(libname, hfile);
if libisloaded(dllName)
disp(["the library “, dllName, " is loaded successfully!”])
end
libfunctions(dllName);
calllib(dllName, ‘init_julia’, 0, {‘’});
calllib(dllName, funName, 7232, 1); % to realize 7232 + 1
calllib(dllName, ‘shutdown_julia’, 0);
unloadlibrary(dllName);
"
The code can be executed in step-by-step mode. But when the script is executed in the command window, matlab will shut down unexpectedly.

If you are referring to the issue were it can not be run twice in the same Matlab session, I had this issue too.

Do not call the shutdown_julia function until you plan on exiting MATLAB.

I have to say, I feel this should be possible and is an issue of Julia and not Matlab.

If I have time, I will try if the same behaviour can be observed with other callers e.g. a C++ or C# app or even another Julia session.

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:

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.

I think that it would be better to both call and release a Julia shared library as required, otherwise, to add a checking function on available Julia threads before budgeting new ones. The later manner might be a workaround to avoid unnecessarily activating new threads.

  1. Sure, but these are aspirational goals. Here is the current code.
  1. Julia does not dynamically launch threads at the moment. They are allocated on startup. They are only shutdown at process exit at the moment.

Perhaps some of what you would like to accomplish here may be accomplished by StaticCompiler.jl and StaticTools.jl. This would allow a subset of Julia to be compiled into a static function that does not need the Julia runtime and thus does not need initialization or shutdown.

3 Likes

valuable information, I’ll check and compare it with the “runtime” manner. Many thanks!

Doesn’t currently work on Windows

:cry:

Windows Subsystem for Linux 2?