Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the R default C/C++ compiler in Kubuntu Linux

Tags:

linux

r

gcc

clang

If one installs an R package that requires compilation via

R CMD INSTALL package.tar.gz

from the bash, R uses by default the gcc compiler. It happened now that my R-package throws a warning on Cran with a 'clang' compiler setup, that doesn't appear using the gcc compiler.

In order to reproduce the warning now on my local machine, I would like to adjust the local compiler settings to those used on the Cran-check servers.

I found out that it should be possible to change the R default compiler by creating a Makevars.in file somewhere in the home folder, but I cannot find where it has to be located and what has to be written there in order to make R to use 'clang' with certain warning flags enabled instead of 'gcc'.

Has anybody already switched on his/her Linux system the R default compiler from gcc to clang and could give me a hint how to do that?

like image 784
Daniel Fischer Avatar asked Dec 01 '22 19:12

Daniel Fischer


1 Answers

My favourite method (and I think I detailed that here before) is to use the file ~/.R/Makevars where I set

CFLAGS +=             -O3 -Wall -pipe -pedantic -std=gnu99
CXXFLAGS +=           -O3 -Wall -pipe -Wno-unused -pedantic 

#VER=-4.6
#VER=-4.7
VER=-4.8
CC=ccache gcc$(VER)
CXX=ccache g++$(VER)
SHLIB_CXXLD=g++$(VER)
FC=ccache gfortran
F77=ccache gfortran
MAKE=make -j8

#CXX=clang++
#CC=clang

and more as it also allows you to switch to clang++ instead of g++ and more.

I use ccache here too in order to accelerate repeated builds -- very useful for R packages where you may alter the package code but not the src/ files.

An alternative approach would a shell-script wrapper in which you set CC, CXX and everything else you want to modify.

like image 198
Dirk Eddelbuettel Avatar answered Dec 03 '22 23:12

Dirk Eddelbuettel