4

I'm just trying to get Rcpp up and running on my Mac, but am struggling. I've installed the Command Line Tools. I've installed the Rcpp and inline packages. I try to run the following script in R, and get the following error.

fx <- cxxfunction(signature( x = "numeric" ),

  'NumericVector xx(x);

  return wrap( std::accumulate( xx.begin(), xx.end(), 0.0));',

  plugin = "Rcpp",verbose=TRUE)


Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! /bin/sh: llvm-g++-4.2: command not found
make: *** [file2e731b1c0ff8.o] Error 127

I realize this is very similar to a posted question. But I'd appreciate a reference to more details on where to find the makevars file.

Thanks.

Scott
  • 316
  • 3
  • 9

2 Answers2

5

As I alluded to in this previous answer, you must correct the values hard-coded in the R binary provided by CRAN which was built with the old XCode which still had the g++-based compiler. You have (at least) three choices:

  1. Edit etc/Makeconf (below R's install directory) directly to correct CC and CXX to clang and clang++.

  2. Alternatively, create or edit ~/.R/Makevars similarly.

  3. Create environment variables CC and CXX with these loadings.

The long and short of it is that CC and CXX have hard-coded values from R's compile-time which no longer correspond the values on your system (using XCode 5). Eventually, R will catch up and this adjustment will be unnecessary.

The R Installation and Administration manual has more to say about which variables and which values you should use on a given architecture.

Community
  • 1
  • 1
Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • Thanks, I chose option 1, and it seems like everything is ok. Now to start on learning to use Rcpp! – Scott Oct 24 '13 at 00:47
  • Sure thing -- and do come over to the rcpp-devel list too for questions. Oh, and please feel free to 'accept' the answer by clicking on the tick mark symbol. – Dirk Eddelbuettel Oct 24 '13 at 02:19
3

Since g++ is no longer included in Xcode 5, you will have to re-direct the pointers to clang. Based on @Romain Francois' answer from Error when with Xcode 5.0 and Rcpp (Command Line Tools ARE installed), you will have to create your own Makevars file in the ~/.R/ directory. Example content of Makevars would contain:

CC=clang
CXX=clang++
CFLAGS="-mtune=native -g -O2 -Wall -pedantic -Wconversion"
CXXFLAGS="-mtune=native -g -O2 -Wall -pedantic -Wconversion"
FLIBS=-lgfortran
Community
  • 1
  • 1