This example code previously appeared on a blog posting by Aditya, with one minor adjustments. I tried to run it on Debian 10 (buster), but it failed with the following error.
texlua julia.lua
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
I tried this with both the default Julia version 1.0.3+dfsg-4
, as well as the current unstable version 1.1.1+dfsg-1
. In both cases this produced the error shown above. I'm also using a backport of TeX Live 2019 from Debian unstable (Debian 10/buster just has the prerelease), with LuaTeX 1.10.0.
Two different people report this code working for them on Arch Linux. One of them is Aditya.
To quote him from chat:
On my system, the library that should be loaded is libjulia.so and is located at /usr/lib/libjulia.so
On my Debian system, julia/sys.so
is installed, but I'm not sure why it's not being found.
dlocate julia/sys.so
libjulia1: /usr/lib/x86_64-linux-gnu/julia/sys.so
The code follows.
local ffi = require("ffi")
local JULIA = ffi.load("julia", true)
ffi.cdef [[
void jl_init__threading(void);
typedef struct _jl_value_t jl_value_t;
jl_value_t *jl_eval_string(const char*);
]]
JULIA.jl_init__threading()
code = [[
x = [1 2 3]'
A = [1 0 1; 0 1 1; 1 1 0]
y = x'*A*x
print(y[1])
]]
JULIA.jl_eval_string(code)