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

Gow, Ian igow at hbs.edu
Wed Apr 23 12:57:34 CEST 2014


Josh:

I see the same issue. But it appears not to be a problem with the point_mcmc.cpp version of the code. If I issue sourceCpp('point_mcmc.cpp') from within R, it works fine. sourceCpp('point_mcmc.cpp', verbose=TRUE) gives further hints (i.e., effect of R CMD SHLIB is different from within R; see below).

A little Googling turns up the following answer to your question:

> You want to set PKG_CXXFLAGS -- see the fine manual's Section 1.2. "Using Makevars" as well as Section 5.5 "Creating shared objects" for details."
Source: Dirk Eddelbuettel, http://stackoverflow.com/questions/12416463/how-to-specify-header-search-path-when-using-r-cmd-shlib-to-compile-a-c-file

This is also helpful:
http://people.math.aau.dk/~sorenh/misc/Rdocs/Rcpp/RcppSHLIB.html

-Ian

>From command line:
$ /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB -o 'sourceCpp_67823.so' --preclean '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> // include
         ^
1 error generated.
make: *** [point_mcmc.o] Error 1

>From within R:
/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB -o 'sourceCpp_67823.so' --preclean '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  -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include"    -fPIC  -Wall -mtune=core2 -g -O2  -c point_mcmc.cpp -o point_mcmc.o

On Apr 23, 2014, at 3:04 AM, Josh EmBree <jembree at ucla.edu> wrote:

> 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 
> _______________________________________________
> R-SIG-Mac mailing list
> R-SIG-Mac at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac



More information about the R-SIG-Mac mailing list