Non-Contradiction / JuliaCall

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

could not load symbol "SuiteSparse_config_malloc_func_set" with julia 1.10.0 and R 4.1.2 on Linux during julia_setup #224

Open Alexander-Barth opened 5 months ago

Alexander-Barth commented 5 months ago

I am trying to install JuliaCall with R 4.1.2 and julia 1.10.0. Unfortunately the installation fails due to SuiteSparse. R (on Ubuntu 22.04) uses suite sparse config version 5.10 however (/usr/lib/x86_64-linux-gnu/libsuitesparseconfig.so.5) however julia 1.10 is bundeld with version 7.2.1 (<julia-installation>/lib/julia/libsuitesparseconfig.so.7.2.1).

library(JuliaCall);  
julia_setup(verbose=TRUE)

This produces the following error:

Julia version 1.10.0 at location /mnt/data1/abarth/opt/julia-1.10.0/bin will be used.

Loading setup script for JuliaCall...
┌ Error: Error during initialization of module CHOLMOD
│   exception =
│    could not load symbol "SuiteSparse_config_malloc_func_set":
│    /usr/lib/x86_64-linux-gnu/libsuitesparseconfig.so.5: undefined symbol: SuiteSparse_config_malloc_func_set
│    Stacktrace:
│      [1] __init__()
│        @ SparseArrays.CHOLMOD /mnt/data1/abarth/opt/julia-1.10.0/share/julia/stdlib/v1.10/SparseArrays/src/solvers/cholmod.jl:224
│      [2] run_module_init(mod::Module, i::Int64)
│        @ Base ./loading.jl:1128
│      [3] register_restored_modules(sv::Core.SimpleVector, pkg::Base.PkgId, path::String)
│        @ Base ./loading.jl:1116
│      [4] _include_from_serialized(pkg::Base.PkgId, path::String, ocachepath::String, depmods::Vector{Any})
│        @ Base ./loading.jl:1061
│      [5] _tryrequire_from_serialized(modkey::Base.PkgId, path::String, ocachepath::String, sourcepath::String, depmods::Vector{Any})
│        @ Base ./loading.jl:1475
│      [6] _require_search_from_serialized(pkg::Base.PkgId, sourcepath::String, build_id::UInt128)
│        @ Base ./loading.jl:1568
│      [7] _require(pkg::Base.PkgId, env::String)
│        @ Base ./loading.jl:1932
│      [8] __require_prelocked(uuidkey::Base.PkgId, env::String)
│        @ Base ./loading.jl:1806
│      [9] #invoke_in_world#3
│        @ Base ./essentials.jl:921 [inlined]
│     [10] invoke_in_world
│        @ Base ./essentials.jl:918 [inlined]
│     [11] _require_prelocked(uuidkey::Base.PkgId, env::String)
│        @ Base ./loading.jl:1797
│     [12] macro expansion
│        @ Base ./loading.jl:1784 [inlined]
│     [13] macro expansion
│        @ Base ./lock.jl:267 [inlined]
│     [14] __require(into::Module, mod::Symbol)
│        @ Base ./loading.jl:1747
│     [15] #invoke_in_world#3
│        @ Base ./essentials.jl:921 [inlined]
│     [16] invoke_in_world
│        @ Base ./essentials.jl:918 [inlined]
│     [17] require(into::Module, mod::Symbol)
│        @ Base ./loading.jl:1740
│     [18] top-level scope
│        @ ~/R/x86_64-pc-linux-gnu-library/4.1/JuliaCall/julia/setup.jl:13
│     [19] include(mod::Module, _path::String)
│        @ Base ./Base.jl:495
│     [20] top-level scope
│        @ none:1
└ @ SparseArrays.CHOLMOD /mnt/data1/abarth/opt/julia-1.10.0/share/julia/stdlib/v1.10/SparseArrays/src/solvers/cholmod.jl:241
Finish loading setup script for JuliaCall.

In the past, I could resolve similar issues by setting LD_PRELOAD or LD_LIBRARY_PATH forcing the loading of the newer library, for example:

export LD_PRELOAD=/mnt/data1/abarth/opt/julia-1.10.0/lib/julia/libsuitesparseconfig.so.7.2.1

before starting R. But I get the same error as above (/usr/lib/x86_64-linux-gnu/libsuitesparseconfig.so.5: undefined symbol: SuiteSparse_config_malloc_func_set).

I don't have these issues with julia 1.6.2 as both use the same version of this library.

Any ideas how this issue can be resolved (besides rebuilding R with the same libraries as Julia)?

Thank you very much for this nice package and your efforts to bridge the R and Julia communities 😀

Session Info ``` > sessionInfo() R version 4.1.2 (2021-11-01) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 22.04.3 LTS Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=en_US.UTF-8 LC_NAME=en_US.UTF-8 [9] LC_ADDRESS=en_US.UTF-8 LC_TELEPHONE=en_US.UTF-8 [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] JuliaCall_0.17.5 loaded via a namespace (and not attached): [1] compiler_4.1.2 tools_4.1.2 Rcpp_1.0.12 knitr_1.45 xfun_0.41 ```
Alexander-Barth commented 5 months ago

In fact, on Ubuntu libsuitesparseconfig5 is not a dependency of R. If I remove it, I can use julia 1.10 and R together.

It seems that the issue is that R sets its LD_LIBRARY_PATH (probably here):

$ echo $LD_LIBRARY_PATH

abarth@work:~ 
$ R -q
> Sys.getenv("LD_LIBRARY_PATH")
[1] "/usr/lib/R/lib:/usr/lib/x86_64-linux-gnu:/usr/lib/jvm/default-java/lib/server"
> 

Probably any library installed in these paths will shadow a julia library of the same name. The somewhat bizarre work-around is to add the julia library directory to R_LD_LIBRARY_PATH which works even when there is a libsuitesparseconfig5 installed.

$ export R_LD_LIBRARY_PATH="/mnt/data1/abarth/opt/julia-1.10.0/lib/julia/:/usr/lib/R/lib:/usr/lib/x86_64-linux-gnu"
abarth@work:~ 
$ R -q
> library(JuliaCall)
> julia_setup()
Julia version 1.10.0 at location /mnt/data1/abarth/opt/julia-1.10.0/bin will be used.
Loading setup script for JuliaCall...
Finish loading setup script for JuliaCall.
ahazra commented 1 month ago

Setting alias julia='LD_LIBRARY_PATH=" " julia' seems to have solved the problem. But how can I set this configuration in VSCODE? It would be great if anyone can inform me.