I am trying the basic example of embedding Julia in C:
file a.c
contains
#include <julia.h>
int main(void) {
jl_init();
(void) jl_eval_string("print(sqrt(2.))");
return 0;
}
and the Makefile is also copy-pasted from the example:
JL_SHARE = $(shell julia -e 'print(joinpath(Sys.BINDIR, Base.DATAROOTDIR, "julia"))')
CFLAGS += $(shell $(JL_SHARE)/julia-config.jl --cflags)
CXXFLAGS += $(shell $(JL_SHARE)/julia-config.jl --cflags)
LDFLAGS += $(shell $(JL_SHARE)/julia-config.jl --ldflags)
LDLIBS += $(shell $(JL_SHARE)/julia-config.jl --ldlibs)
all: a
The thing compiles fine, yet on execution fails with
ERROR: could not load library "/usr/lib/x86_64-linux-gnu/../bin/../lib/x86_64-linux-gnu/julia/sys.so"
/usr/lib/x86_64-linux-gnu/../bin/../lib/x86_64-linux-gnu/julia/sys.so: cannot open shared object file: No such file or directory
This is a plain Debian testing installation, with Julia from the Debian repository; version 1.5.3. The correct location for sys.so
would be /usr/lib/x86_64-linux-gnu/julia/sys.so
; yet the path used above has either an extra /bin
component, or is lacking one /..
.
The output of julia-config.jl --allflags
seems fine:
-std=gnu99 -I'/usr/include/julia' -fPIC -L'/usr/lib/x86_64-linux-gnu' -Wl,--export-dynamic -Wl,-rpath,'/usr/lib/x86_64-linux-gnu' -Wl,-rpath,'/usr/lib/x86_64-linux-gnu/julia' -ljulia
and the binary ./a
is also able to find libjulia.so.1
. So the path confusion likely happens somewhere inside libjulia. What did I do wrong, and how can I fix this?
(apart from creating a stupid symlink to add a file in the wrong place in the filesystem, of course)
The julia
binary itself, of course, works well and can even correctly locate sys.so
:
julia> Libdl.dlpath("sys.so")
"/usr/lib/x86_64-linux-gnu/julia/sys.so"