Hello, I am still trying to call Julia from C++
Here is my Julia
f(x::Int32)::Int32 = x + 3
Following these directions
[Embedding Julia · The Julia Language](http://Manual >> Embedding Julia)
[Redirecting to Google Groups](http://calling julia functions in C++)
I am calling
double ret_unboxed = 0;
jl_value_t *mod = jl_eval_string("TestF");
jl_function_t *func = jl_get_function((jl_module_t*)mod, "f");
jl_value_t *argument = jl_box_int32(x);
jl_value_t *ret = jl_call1(func, argument);
ret_unboxed = jl_unbox_int32(ret);
Unfortunately, I get 0 for both mod and func.
First question: is jl_eval_string() really the best way to get the module?
Second question: can anyone point me to more documentation and/or a real working example of calling Julia functions from C?
If you get 0 for both
func, then there seems to be something wrong with the execution of the julia code
module Test F .... end in the embedding julia. And there is no code in your example which does this.
Did you forget to execute
module Test F ... end after
jl_init()? Or if you did it, what was your method?
That is all my C code. How do I execute my module?
You could use something like
jl_eval_string("Base.include(Main, the location of your julia file)") to execute your module for julia 0.7 and 1.0, or
jl_eval_string("include(the location of your julia file)") for julia 0.6. And then you should be able to find your module and your function.
Plus, this is an R package of mine which embeds julia in R through c/cpp, https://github.com/Non-Contradiction/JuliaCall, but the embedding related code is separated in R/cpp/julia codes, so it may not be a very good first example.
Thanks, but I am now confused.
What is the point of compiling and linking my Julia code if I am just going to invoke the REPL?
PackageCompiler produces a 14MB library from my tiny code. Surely this must include everything I need already compiled and ready to go.
If you have already use PackageCompiler for your module, then it should be fine just by linking the generated shared library to your c code or using the generated new system image as far as I know. I think the best examples are in the repo itself: https://github.com/JuliaLang/PackageCompiler.jl.