I find correctly initializing it is a bit tricky. But it works for me:
from pathlib import Path
import ctypes
libpath = Path(__file__).resolve().parent.joinpath("builddir", "test.so")
dll = ctypes.CDLL(libpath, ctypes.RTLD_GLOBAL)
dll.func0.restype = ctypes.c_double
dll.func1.restype = ctypes.c_double
try:
jl_init_with_image = dll.jl_init_with_image
except AttributeError:
jl_init_with_image = dll.jl_init_with_image__threading
jl_init_with_image.argtypes = [ctypes.c_char_p, ctypes.c_char_p]
if __name__ == "__main__":
jl_init_with_image(None, str(libpath).encode("utf-8"))
print("func1 =", dll.func1())
print("func0 =", dll.func0())