Jl_get_function() throwing Segmentation fault

For future users that encounter the same problem:

If you dlopen libjulia when embedding there will be some symbols that won’t be dlsymed as jl_get_function().

Instead of doing what every documentation suggests, at least in Julia v1.3.1. , you need to use jl_get global() as I do here:

jl_init();
jl_value_t *mod = jl_eval_string("Base");
jl_function_t *sqrt = (jl_function_t*)jl_get_global((jl_module_t*)mod,jl_symbol("sqrt"));

jl_value_t* argument = jl_box_float64(2.0);
jl_value_t* ret = jl_call1(sqrt, argument);
double retDouble = jl_unbox_float64(ret);
printf("sqrt(2.0) in C: %e\n", retDouble);
jl_atexit_hook(0);

dlsyming every method from libjulia before this.

1 Like