10

Question

I'm trying to tell my package to use gcc to compile the C++ code in stead of clang. Why aren't my CXX flags in my Makevars file being used?

(I am expecting/hoping the solution to be something really simple that I've overlooked.)


It's my understanding (see references) that I can specify CXX* flags in either

  1. src/Makevars in the package, or
  2. ~/.R/Makevars

However, I can't get option 1 to work, only option 2.

Example Builds

Here are screenshots showing the build options I'm using. In each case I'm showing both the Makevars and the /.R/Makevars files to show which one I'm using in each case.

Option 1: src/Makevars

Here I specify CXX11 = /usr/local/bin/g++-7 inside src/Makevars. The build messages say it's building with clang

enter image description here

Option 2: ~/.R/Makevars

Here I specify CXX11 = /usr/local/bin/g++-7 inside ~/.R/Makevars. The build message shows it builds with g++

enter image description here

Example package

I've noticed this on a few packages I've built recently using Rcpp, but if you want an example to test my googlePolylines package is here on github.


References

Session Info

devtools::session_info()
Session info ----------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.4.3 (2017-11-30)
 system   x86_64, darwin15.6.0        ## Mac OS
 ui       RStudio (1.1.414)           
 language (EN)                        
 collate  en_AU.UTF-8                 
 tz       Australia/Melbourne         
 date     2018-03-11 
SymbolixAU
  • 25,502
  • 4
  • 67
  • 139
  • 1
    Your package mustn’t override the C++ compiler(/version) used to compile packages. Otherwise R wouldn’t be able to load it. Hence R forbids this. For the same reason your R package distribution (on GitHub) shouldn’t include the `src/*.o` files. – Konrad Rudolph Mar 12 '18 at 18:29
  • right! I hadn't correctly set up the `.gitignore` and those `.o`s were committed erroneously. I've now cleand up the github repo – SymbolixAU Mar 12 '18 at 19:45

1 Answers1

8

Quoting Duncan Murdoch in https://stat.ethz.ch/pipermail/r-package-devel/2017q4/002087.html:

According to section 1.2.1 "Using Makevars" in Writing R Extensions, R_HOME/etcR_ARCH/Makeconf is included after Makevars, so what you're seeing is by design. I believe this is so that packages are built with tools compatible with those that built R. (Remember, packages are designed for distribution to diverse systems.)

So you might change various flags within src/Makevars via for example PKG_CXXFLAGS, but you cannot overwrite CXXFLAGS or CXX itself. And there is no PKG_CXX.

Ralf Stubner
  • 26,263
  • 3
  • 40
  • 75