Discussion:
Embedding Julia
Herbert Sauro
2014-06-09 04:59:38 UTC
Permalink
I've been thinking of embedding Julia in one of my applications as a saw
some example C code that showed how this could be done
(http://docs.julialang.org/en/latest/manual/embedding/). As an experiment I
tried to initialize Julia from Delphi (Object Pascal) on Windows 7.

I downloaded the windows 32-bit binaries and unpacked the files. I noticed
the file libjulia.dll in bin and discovered that jl_init was exported from
this dll. I therefore loaded the libjulia.dll and called jl_init (NULL) but
got an access violation. I assumed cdecl calling conventions (also I tried
stdcall just in case). I also tried passing the julia home directory (tried
various combinations) to the init method but that didn't work either.

Is there something else I must do to initialize Julia? Does Julia expect
certain environment variables to be setup?

Any suggestion gratefully received.

Herbert
Tobias Knopp
2014-06-09 06:32:05 UTC
Permalink
do you use a 0.3 prerelease?

If I recall correctly passing NULL also did not work when I embedded Julia
in C using MSVC.
I am currently not sure if I then passed the Julia installation dir or
some of the subdirs (bin or lib)
Post by Herbert Sauro
I've been thinking of embedding Julia in one of my applications as a saw
some example C code that showed how this could be done (
http://docs.julialang.org/en/latest/manual/embedding/). As an experiment
I tried to initialize Julia from Delphi (Object Pascal) on Windows 7.
I downloaded the windows 32-bit binaries and unpacked the files. I noticed
the file libjulia.dll in bin and discovered that jl_init was exported from
this dll. I therefore loaded the libjulia.dll and called jl_init (NULL) but
got an access violation. I assumed cdecl calling conventions (also I tried
stdcall just in case). I also tried passing the julia home directory (tried
various combinations) to the init method but that didn't work either.
Is there something else I must do to initialize Julia? Does Julia expect
certain environment variables to be setup?
Any suggestion gratefully received.
Herbert
Herbert Sauro
2014-06-09 16:32:39 UTC
Permalink
Thanks for the rely, I'm using 0.2.1. Do you think I might have better luck with o.3 prerelease?

Herbert
Tobias Knopp
2014-06-09 16:54:46 UTC
Permalink
Yes, The embedding chapter that you have read was written after the 0.2 was
released. I have fixed some export issues during the 0.3 release cycle that
are not in 0.2.
Post by Herbert Sauro
Thanks for the rely, I'm using 0.2.1. Do you think I might have better
luck with o.3 prerelease?
Herbert
Herbert Sauro
2014-06-09 18:25:04 UTC
Permalink
I tried 0.3 prelease but got the same error when calling jl_init(). I tried
the following:

I used the method signature: void jl_init (char *), and loading finds the
method ok

Tried libjulia.dll and libjulia-debug.dll

Tried cdecl and stdcall conventions on jl_init()

Tried calling with NULL and a pointer to the julia home directory
(including various combinations of paths)

julia.exe launches ok

All binaries were in directory c:\julia30 (i.e no spaces in path names)

Called prepare-julia-env.bat in case that was required.

What I will try next is calling jl_init() in Visual studio just in case
there is a Delphi issue (but I've done a lot of dll calling from Delphi so
I would be surprised if that id the problem, but you never know).

Herbert
Post by Tobias Knopp
Yes, The embedding chapter that you have read was written after the 0.2
was released. I have fixed some export issues during the 0.3 release cycle
that are not in 0.2.
Post by Herbert Sauro
Thanks for the rely, I'm using 0.2.1. Do you think I might have better
luck with o.3 prerelease?
Herbert
Herbert Sauro
2014-06-09 23:26:43 UTC
Permalink
For those who might be interested here is an update. I called libjulia.dll
from a straight C application using Visual Studio 2010 and it work ok. So
something odd with Delphi. Delphi can be used to develop two types of
application, Console or GUI apps. I was calling libjulia.dll from a GUI
app. Out of curiosity I tried calling the julia dll from a console Delphi
app and that worked. Never seen this behavior before so I am asking some of
my Delphi colleagues to see if they have an explanation. The only thing I
can think of is that maybe libjulia is doing something with
stdin/stdout/stderr which isn't compatible with the GUI application.
Herbert Sauro
2014-06-10 00:39:32 UTC
Permalink
I've answered my own question, I have to redirect stdout etc in order to use julia in a GUI application.

Herbert
Tobias Knopp
2014-06-10 07:11:21 UTC
Permalink
Great that it is working now! Where did you redirect from Julia or from
Delphi? I think it would be really great if you could post a small example
how you get this working. Either it is a bug that we can solve in libjulia
or it is a workaround which should go into the documentation.

Thanks

Tobi
Post by Herbert Sauro
I've answered my own question, I have to redirect stdout etc in order to
use julia in a GUI application.
Herbert
Continue reading on narkive:
Loading...