[R-SIG-Mac] Rcpp w/ OS X Mavericks

Josh EmBree jembree at ucla.edu
Wed Apr 23 09:04:44 CEST 2014


Hi all, 

I know this issue has come up a lot in the last few months and I’ve searched around for days trying to find a solution. I can’t get my C++ files that use Rcpp to compile in OS X 10.9 (Mavericks). I’ve done the following:

-Downloaded Xcode 5 and installed command line tools, 
-Upgraded to R 3.1 for Mavericks, and
-Installed Rcpp from source. 

After installing Rcpp from source, I can write C++ functions using Inline. For example, 

library(Rcpp)
library(inline)

cppFunction('
double meanC(NumericVector x) {
  int n = x.size();
  double total = 0;

  for(int i = 0; i < n; ++i) {
    total += x[i] / n;
  }
  return total;
}'
            )

works just fine, but the file containing 

#include <Rcpp.h>
using namespace Rcpp;

// [[Rcpp::export]]
double meanC(NumericVector x) {
  int n = x.size();
  double total = 0;

  for(int i = 0; i < n; ++i) {
    total += x[i] / n;
  }
  return total;
}


will not compile. I get the error message:

 $ R CMD SHLIB point_mcmc.cpp
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG  -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include    -fPIC  -Wall -mtune=core2 -g -O2  -c point_mcmc.cpp -o point_mcmc.o
point_mcmc.cpp:1:10: fatal error: 'Rcpp.h' file not found
#include <Rcpp.h>
         ^
1 error generated.
make: *** [point_mcmc.o] Error 1

The fact that one works and the other does not is incredibly confusing. Thanks in advance for any assistance. 

Best, 
Josh 


More information about the R-SIG-Mac mailing list