I was trying to use jl_get_function() julia.h method to call a method implemented on a different .jl file in julia, being both files in the same directory and on Julia1.3.1 .
jl_init(); jl_eval_string("include(\"function.jl\")"); jl_value_t *mod = jl_eval_string("Fun"); jl_function_t *add = jl_get_function((jl_module_t*)mod,"add"); jl_value_t *args; args = jl_box_int32(6); args = jl_box_int32(6); int *res = jl_unbox_int32(jl_call(add,args,2)); printf("Res: %d\n",res); jl_atexit_hook(0);
module Fun add(x,y) = x+y end
When I run my c file called get function.c this occurs, and because of debug prints I used I can tell it occurs when calling jl_get_function():
signal (11): Segmentation fault in expression starting at none:0 unknown function (ip: 0xffffffffffffffff) __libc_start_main at /lib/x86_64-linux-gnu/libc.so.6 (unknown line) unknown function (ip: 0xffffffffffffffff) Allocations: 2451 (Pool: 2442; Big: 9); GC: 0 Segmentation fault
I checked this example file https://github.com/JuliaLang/julia/blob/master/test/embedding/embedding.c
and I’ve notice that it uses jl_main_module when calling jl_get_function() as module argument, I’ve also tried that but the same error occurred.
Any idea on what I do wrong? I can’t figure out because there is not that many documentation about calling your own implemented methods using jl_get_function so I hope someone can help me.