Segfault when jl_init in R (also python?) with julia 1.6 on macOS

A work-around is to change the process cwd to the libjulia path before calling jl_init*. This allows the failing internal dlopen call to succeed, because one of the dlopen search locations is cwd:

import ctypes, os
libjl = ctypes.CDLL("/opt/Julia-1.6.app/Contents/Resources/julia/lib/libjulia.dylib")

libjl.jl_get_libdir.restype = ctypes.c_char_p

prev = os.getcwd()
os.chdir(libjl.jl_get_libdir())
libjl.jl_init__threading()
os.chdir(prev)

(x-ref https://github.com/JuliaLang/julia/issues/40246#issuecomment-912223287 and https://github.com/JuliaPy/pyjulia/issues/437#issuecomment-912223632)

1 Like