JuliaInterop / JuliaCall

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

julia_setup() segmentation fault #179

Open jjlynch2 opened 2 years ago

jjlynch2 commented 2 years ago

I'm receiving a segmentation fault when running julia_setup(). I've tried various parameters including install=TRUE and rebuild=TRUE. I've also reinstalled both Julia and R multiple times rebuilding their libraries entirely. Everything was working previously until I updated both R and Julia. I am able to install and load RCall within Julia. I've verified that the correct Julia path is being used in R and the correct R path is being used in Julia. I'm not sure what else to try at this point.

This is happening on Archlinux with 5.17.1-zen1-1-zen kernel, R version 4.1.3, and Julia version 1.7.2:

System info:

[user@system ~]$ uname -a
Linux system 5.17.1-zen1-1-zen #1 ZEN SMP PREEMPT Mon, 28 Mar 2022 21:56:46 +0000 x86_64 GNU/Linux

R version:

> version
               _                           
platform       x86_64-pc-linux-gnu         
arch           x86_64                      
os             linux-gnu                   
system         x86_64, linux-gnu           
status                                     
major          4                           
minor          1.3                         
year           2022                        
month          03                          
day            10                          
svn rev        81868                       
language       R                           
version.string R version 4.1.3 (2022-03-10)
nickname       One Push-Up  

Julia version:

julia> versioninfo()
Julia Version 1.7.2
Commit bf53498635 (2022-02-06 15:21 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU E3-1505M v5 @ 2.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, skylake)

Segmentation fault:

> julia_setup(verbose=TRUE)

signal (11): Segmentation fault
in expression starting at none:0
__strlen_avx2 at /usr/bin/../lib/libc.so.6 (unknown line)
printf_positional at /usr/bin/../lib/libc.so.6 (unknown line)
__vfprintf_internal at /usr/bin/../lib/libc.so.6 (unknown line)
__vsprintf_internal at /usr/bin/../lib/libc.so.6 (unknown line)
__sprintf_chk at /usr/bin/../lib/libc.so.6 (unknown line)
symbol_suffix_search at /lib/libblastrampoline.so (unknown line)
autodetect_symbol_suffix at /lib/libblastrampoline.so (unknown line)
lbt_forward at /lib/libblastrampoline.so (unknown line)
#lbt_forward#7 at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/LinearAlgebra/src/lbt.jl:158
lbt_forward##kw at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/LinearAlgebra/src/lbt.jl:158 [inlined]
__init__ at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/LinearAlgebra/src/LinearAlgebra.jl:533
jfptr___init___49299.clone_1 at /usr/lib/julia/sys.so (unknown line)
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2247 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2429
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1788 [inlined]
jl_module_run_initializer at /buildworker/worker/package_linux64/build/src/toplevel.c:73
_finish_julia_init at /buildworker/worker/package_linux64/build/src/init.c:796
julia_init at /buildworker/worker/package_linux64/build/src/init.c:730
jl_repl_entrypoint at /buildworker/worker/package_linux64/build/src/jlapi.c:695
main at /buildworker/worker/package_linux64/build/cli/loader_exe.c:42
__libc_start_call_main at /usr/bin/../lib/libc.so.6 (unknown line)
__libc_start_main at /usr/bin/../lib/libc.so.6 (unknown line)
_start at /usr/bin/julia (unknown line)
Allocations: 2722 (Pool: 2713; Big: 9); GC: 0

signal (11): Segmentation fault
in expression starting at none:0
__strlen_avx2 at /usr/bin/../lib/libc.so.6 (unknown line)
printf_positional at /usr/bin/../lib/libc.so.6 (unknown line)
__vfprintf_internal at /usr/bin/../lib/libc.so.6 (unknown line)
__vsprintf_internal at /usr/bin/../lib/libc.so.6 (unknown line)
__sprintf_chk at /usr/bin/../lib/libc.so.6 (unknown line)
symbol_suffix_search at /lib/libblastrampoline.so (unknown line)
autodetect_symbol_suffix at /lib/libblastrampoline.so (unknown line)
lbt_forward at /lib/libblastrampoline.so (unknown line)
#lbt_forward#7 at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/LinearAlgebra/src/lbt.jl:158
lbt_forward##kw at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/LinearAlgebra/src/lbt.jl:158 [inlined]
__init__ at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/LinearAlgebra/src/LinearAlgebra.jl:533
jfptr___init___49299.clone_1 at /usr/lib/julia/sys.so (unknown line)
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2247 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2429
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1788 [inlined]
jl_module_run_initializer at /buildworker/worker/package_linux64/build/src/toplevel.c:73
_finish_julia_init at /buildworker/worker/package_linux64/build/src/init.c:796
julia_init at /buildworker/worker/package_linux64/build/src/init.c:730
jl_repl_entrypoint at /buildworker/worker/package_linux64/build/src/jlapi.c:695
main at /buildworker/worker/package_linux64/build/cli/loader_exe.c:42
__libc_start_call_main at /usr/bin/../lib/libc.so.6 (unknown line)
__libc_start_main at /usr/bin/../lib/libc.so.6 (unknown line)
_start at /usr/bin/julia (unknown line)
Allocations: 2720 (Pool: 2712; Big: 8); GC: 0
sh: line 1: --startup-file=no: command not found
Error in system2(file.path(.julia$bin_dir, "julia"), shQuote(command),  : 
  error in running command

R path in Julia goes to a symbolic link that goes to the R binary

julia> ENV["R_HOME"]
"/usr/lib64/R"

julia> RCall.Rhome
"/usr/lib64/R"

R path in system:

[user@system ~]$ ls -asl /usr/lib64/R/bin/R
0 lrwxrwxrwx 1 root root 14 Mar 10 02:21 /usr/lib64/R/bin/R -> ../../../bin/R

[user@system ~]$ which R
/usr/bin/R

Julia path in R:

> system2("bash", "-l -c 'which julia'", stdout = TRUE)[1]
[1] "/usr/bin/julia"

Julia path in system:

[user@system ~]$ which julia
/usr/bin/julia

Some other info:

julia> RCall.libR
"/usr/lib64/R/lib/libR.so"

julia> RCall.validate_libR(RCall.libR)
true

Example showing that RCall is working fine:

julia> x = randn(10)
10-element Vector{Float64}:
  0.7241615511171315
  1.4127185752938043
  2.036454123602012
  2.069693934325717
  0.3741145276632455
 -0.5874128978678226
 -0.6492941008456496
  0.07825536684789963
  0.19885858673446574
 -0.0632804906105466

julia> R"t.test($x)"
RObject{VecSxp}

    One Sample t-test

data:  `#JL`$x
t = 1.7913, df = 9, p-value = 0.1068
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
 -0.147038  1.265892
sample estimates:
mean of x 
0.5594269 
thomarse-ef commented 2 years ago

I'm also having this issue, same set up and versions as OP

thomarse-ef commented 2 years ago

I've found that if I run R directly from the Linux terminal (rather than through RStudio) julia_setup works fine, as do other JuliaCall functions thereafter. I also noticed that if I try to open Julia from the terminal within RStudio (with julia command) I get the same segmentation fault error as above. So the issue appears to be something to do with RStudio.

RStudio info: RStudio 2022.02.1+461 "Prairie Trillium" Release (fc9e217, 2022-04-07) for x86_64 GNU/Linux Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.15.9 Chrome/87.0.4280.144 Safari/537.36

feinmann commented 1 year ago

Same here: I get only the segmentation fault if I run JuliaCall::julia_setup() inside RStudio-R-console. Except, when I run R from the RStudio-integrated terminal, everything works as expected, contrary to what thomarse-ef said. So the problem is only when I use the RStudio-integrated- R-console. Any ideas?

> Sys.getenv("R_HOME")
[1] "/usr/lib64/R"

> version
               _                           
platform       x86_64-pc-linux-gnu         
arch           x86_64                      
os             linux-gnu                   
system         x86_64, linux-gnu           
status                                     
major          4                           
minor          2.2                         
year           2022                        
month          10                          
day            31                          
svn rev        83211                       
language       R                           
version.string R version 4.2.2 (2022-10-31)
nickname       Innocent and Trusting 

julia> versioninfo()
Julia Version 1.8.5
Commit 17cfb8e65e* (2023-01-08 06:45 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: 8 × 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, tigerlake)
  Threads: 1 on 8 virtual cores
Environment:
  LD_LIBRARY_PATH = /usr/lib64/R/lib:/lib:/usr/lib/jvm/java-18-openjdk/lib/server