Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set CXXFLAGS in Rcpp Makevars

Tags:

c++

r

rcpp

I would like to set the C++ compiler flag to -O0 in the Makevars of an Rcpp project.

If I take a look at /etc/R/Makeconf, I see that the compilation command seems to be

$(CXX) $(ALL_CPPFLAGS) $(ALL_CXXFLAGS) -c $< -o $@

Since

ALL_CXXFLAGS = $(R_XTRA_CXXFLAGS) $(PKG_CXXFLAGS) $(CXXPICFLAGS) $(SHLIB_CXXFLAGS) $(CXXFLAGS)

I can edit in the Makevars the variable $(PKG_CXXFLAGS) to add headers for specific libraries, but I am not satisfied with CXXFLAGS = -O3 -pipe -g $(LTO). I would also like to be able to do that directly in the Makevars, so as to tune each project according to my needs.

When I edit CXXFLAGS in the Makevar, nothing happens. Is is possible to adjust that variable ? Is another approach possible ? I know that I can edit ~/.R/Makevars, and switch as requested. I wondered if there was a more robust approach.

like image 766
vkubicki Avatar asked Mar 21 '14 09:03

vkubicki


1 Answers

You generally want the PKG_* variants in your local file, e.g. ~/.R/Makevars.

Here is a (shortened, edited) portion of mine:

## for C code
CFLAGS=               -O3 -g0 -Wall -pipe -pedantic -std=gnu99 

## for C++ code
#CXXFLAGS=             -g -O3 -Wall -pipe -Wno-unused -pedantic -std=c++11
CXXFLAGS=             -g -O3 -Wall -pipe -Wno-unused -pedantic 

## for Fortran code
#FFLAGS=-g -O3 -Wall -pipe
FFLAGS=-O3 -g0 -Wall -pipe
## for Fortran 95 code
#FCFLAGS=-g -O3 -Wall -pipe
FCFLAGS=-O3 -g0 -Wall -pipe

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

The other (system-global) approach is to create and edit /etc/R/Makeconf.site (or, when /etc/R/ does not exist, $RHOME/etc/R/Makeconf.site.

like image 50
Dirk Eddelbuettel Avatar answered Oct 11 '22 22:10

Dirk Eddelbuettel