Mazin Abdelghany
Mazin Abdelghany

Reputation: 31

Unable to install some R packages in Ubuntu 20.04 because of internal compiler error: Segmentation fault

I've recently installed R version 4.0.5 (2021-03-31) onto Ubuntu 20.04.2 LTS. R is working as expected.

However, while some packages have installed without issue (e.g., R.matlab), there are several packages that have not been able to install. As as example, running install.packages("data.table") throws the following error:

* installing *source* package ‘data.table’ ...
** package ‘data.table’ successfully unpacked and MD5 sums checked
** using staged installation
gcc -std=gnu99 9.3.0
zlib 1.2.11 is available ok
R CMD SHLIB supports OpenMP without any extra hint
** libs
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG     -fopenmp  -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-tRgc13/r-base-4.0.5=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c assign.c -o assign.o
during GIMPLE pass: ccp
assign.c: In function ‘memrecycle’:
assign.c:1205:1: internal compiler error: Segmentation fault
 1205 | }
      | ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-9/README.Bugs> for instructions.
make: *** [/usr/lib/R/etc/Makeconf:172: assign.o] Error 1
ERROR: compilation failed for package ‘data.table’

I get similar errors (i.e., "internal compiler error") with other package installation attempts, but with slightly different output. For example, install.packages("xfun") throws the following error, truncated for brevity:

gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-tRgc13/r-base-4.0.5=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c base64.c -o base64.o
during GIMPLE pass: ccp
base64.c: In function ‘base64_decode_impl’:
base64.c:237:1: internal compiler error: Segmentation fault
  237 | }
      | ^

I have tried reinstalling gcc-9, which has not helped. I had found that the PATH in Sys.getenv("PATH") was pointing to a miniconda3 install on my system, so updated that to /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/rstudio/bin/postback, which also has not helped.

My goal is to install packages among those above without throwing these compiler errors. Any help would be greatly appreciated.

Upvotes: 1

Views: 1239

Answers (1)

Mazin Abdelghany
Mazin Abdelghany

Reputation: 31

In case others also run into this issue in the future, I am posting the solution that was suggested to me by https://answers.launchpad.net/ubuntu. Here is the link to the question I posted: https://answers.launchpad.net/ubuntu/+question/696623.

The issue turned out to be that R was using gcc-9 rather than gcc-10 to compile packages. The older version of gcc was throwing an error. Here are the steps I took to solve the problem:

  1. Install gcc-10, which was not available on my system: sudo apt install gcc-10.
  2. Edit the CC= pointer in the /usr/lib/R/etc/Makeconf file to gcc-10: open Terminal, type sudo nano /usr/lib/R/etc/Makeconf and replace the current CC= to CC=gcc-10. Save the file.
  3. Restart R and run the install.packages() command for those packages that were not compiling correctly.

EDIT: Please see the comments below for a discussion. The above steps resolve the issue, but are not recommended. The issue was related to R not using the system package manager to install packages when the call install.packages() was used in R.

Installing the package bspm solved the issue for me. This package and its utility is discussed here for those who are curious.

To use install.packages() within R, bspm can be used in two ways:

  1. bspm::enable() within R and then install.packages()
  2. As written in its documentation: To enable bspm system-wide by default, include the following: suppressMessages(bspm::enable()) into the Rprofile.site file.

Thanks very much to Dirk for his guidance.

Upvotes: 2

Related Questions