@AndresGomez97 wrote:
Hi, I am new in Julia and I am trying to run the following code that embeds julia into c.
#include <stdio.h> #include <stdlib.h> #include <dlfcn.h> #include <julia.h> int main(){ void *handle; void (*jl_init_with_image)(const char*, const char*); int (*jl_atexit_hook)(int); void (*jl_eval_string)(const char*); handle = dlopen("$JULIA_DIR/usr/lib/libjulia.so", RTLD_LAZY | RTLD_GLOBAL); if (!handle) { fprintf(stderr, "%s\n", dlerror()); exit(EXIT_FAILURE); } *(void**)(&jl_init_with_image) = dlsym(handle, "jl_init_with_image"); *(int**)(&jl_atexit_hook)= dlsym(handle, "jl_atexit_hook"); *(void**)(&hl_eval_string) = dlsym(handle, "jl_eval_string"); dlerror(); jl_init_with_image("$JULIA_DIR/usr/bin","$JULIA_DIR/usr/lib/julia/sys.ji"); jl_eval_string("print('foo')"); jl_atexit_hook(0); return 0; }
As you can see I am trying to embed it using dlopen to link libjulia shared object instead of doing it with gcc -L option because as I need to make it work with ROOT this is necessary (ROOT and Julia don’t like each other because of LLVM). When I run this program Segmentation fault occurs.
I am using Julia 1.3.0 from git and running this in amd64_linux26 system.
Also using “gcc -Wall file.c -ldl -I’$JULIA_DIR/usr/include/julia’ -o file -JULIA_NUMBER_THREADS=1 -fPIC” for compiling it.
I’ve tried to use jl_init() but it also causes segmentation fault.
Maybe I am not understanding the parameters I need to pass to jl_init() or jl_init_with_image(), but in both cases I am getting a segmentation fault and I don’t know why so some help would be great.
Posts: 7
Participants: 3