[R-SIG-Mac] Automatically detecting and setting CXX compiler using configure/Makevars

Robert Bruggner rbruggner at gmail.com
Tue Oct 8 21:00:21 CEST 2013

Hi all, 

I'm developing a package that needs to be compiled on installation but am unsure how to ensure that the proper C++ compiler is invoked when installing this package from source. Is there anyway to, at build time, auto-detect and set the available compiler using configure / Makevars? 

More specifically, I'm using the CRAN-provided  binary of R 3.02 running on Mac OS 10.8.5 with XCode 5 installed. By default, the Makeconf included with the R installation ($RHOME/Resources/Makeconf) has CXX set as:

CXX = llvm-g++-4.2 -arch x86_64

However, as llvm-g++-4.2 is no longer distributed with XCode5, package installation fails when I attempt to install from source with an expected "llvm-g++-4.2: command not found" message. 

I see that one solution is to manually set CXX in the ~/.R/Makevars file. However,  I'm wondering if it's possible to have the combination of a configure script / Makevars.in automatically detect and set the CXX variable upon installation. 

As I have it specified currently, my configure.ac script use the AC_PROG_CXX macro to detect and set CXX. 

Then, in my Makevars.in, I attempt to specify the value of CXX detected by the configure script

I can then run the configure script manually and, in the produced Makevars file, it appears to detect and set CXX to the proper complier, i.e.:

CXX=g++ -arch x86_64

However, when I then try and install the package, it seems to default back to the using llvm-g++-4.2 as the compiler and thus, installation fails. 

I of course could be approaching this in completely the wrong way. Any suggestions on how I might be able to auto-detect and set the appropriate compiler at build time? 


More information about the R-SIG-Mac mailing list