I am just started using Julia and is interested in embeding julia in C. I
am following this tutorial doc link
<http://docs.julialang.org/en/release-0.4/manual/embedding/>, but can't get
things down even with the simplest demonstration example.
I am using windows, installed Mingw-w64
A first try
I first tried this example which the doc claimed to be simpler
#include <julia.h> int main(int argc, char *argv[]) { jl_init(JULIA_INIT_DIR);
(void)jl_eval_string("println(sqrt(2.0))"); jl_atexit_hook(0); return 0; }
then I compiled it with
C:\Users\qq\AppData\Local\Julia-0.4.6\share\julia\julia-config.jl --cflags
--ldflags --ldlibs | xargs gcc test.c
However, the windows will pop up a dialog ask for what application to open
.jl file
What is wrong? How to use this method on windows? (PS, windows has no
xargs, but I installed GOW toolkilt which provides xargs for windows)
A second try
then I turned to the first example with code
#include <julia.h> int main(int argc, char *argv[]) { /* required: setup the
julia context */ jl_init(NULL); /* run julia commands */
jl_eval_string("print(sqrt(2.0))"); /* strongly recommended: notify julia that
the program is about to terminate. this allows julia time to cleanup pending
write requests and run all finalizers */ jl_atexit_hook(0); return 0; }
then I compiled it with
gcc -o test -I C:\Users\qq\AppData\Local\Julia-0.4.6\include\julia\ -L
C:\Users\qq\AppData\Local\Julia-0.4.6\bin\ test.c -ljulia
C:\Users\qq\AppData\Local\Julia-0.4.6\bin\libstdc++-6.dll
Every thing seems to be OK, it successfully generated a test.exe
But when I run this test.exe, windows pop up a window says " test.exe
stopped working" and I got nothing.
What is wrong? How to correctly compile C embedded with julia correctly on
windows with Mingw-w64 ??