JuliaInterop / JuliaCall

Embed Julia in R
https://non-contradiction.github.io/JuliaCall/index.html
Other
267 stars 36 forks source link

Unable to load Julia Modules That Use Plot: `GLIBCXX_3.4.20' not found #136

Open mattcbro opened 4 years ago

mattcbro commented 4 years ago

The current documentation talks about being unable to load Julia related dynamic libraries due to GLIBCXX_3.4.20. The proposed solution was to add the julia library path to R_LD_LIBRARY_PATH. Setting this does not fix the problem. Indeed in R Sys.getenv(), does not print R_LD_LIBRARY_PATH.

We can set the environment variable LD_LIBRARY_PATH however to nominally fix this problem. However the error still crops up, if in Julia we have a "using Plot" statement. These simple examples show this problem:

First the Julia module FailLoad.jl . The module won't load if the plot code is enabled. If true is replaced with false, however, it will load.

module FailLoad
export hello
if (true) # change to false and it loads
export tryit
using Plots

function tryit()
    plot(1:10, randn(10))
end
end

function hello()
    println("hello")
end

end

Here is the R code that tries to load it. Notice the hoops I jump through to append the julia library path to the end of LD_LIBRARY_PATH and running ldconfig

library(stringr)
# points to my julia library
julialib <- "/home/matt/programs/julia-1.5.1/lib/julia"
# fancy syntax for setenv messes up string interpolation.  Anyway try to set the Library path for this environment
newpath = paste(julialib, sep=":", Sys.getenv("LD_LIBRARY_PATH"))
# the syntax horror begins just to use setenv to append to the end of LD_LIBRARY_PATH
args = list(newpath)
names(args) = "LD_LIBRARY_PATH"
do.call(Sys.setenv, args)
# need to run ldconfig as root to find the libraries, so we launch a graphical interaction for the password
Sys.setenv(SUDO_ASKPASS="/usr/bin/ssh-askpass")
system("sudo -A ldconfig -v")

library(JuliaCall)
julia <- julia_setup()

# make sure current path is in the Julia search space
julia$eval("mypath = pwd()")
julia$eval("push!(LOAD_PATH, mypath)")

# can't load the module because it uses the Plot package
julia_library("FailLoad")
julia$call("hello")