Hi there,
I have a .cpp script I wrote several months ago that I haven't touched in a bit. I source that script using sourceCpp() in my R script. I am now getting the error: fatal error: 'cmath' file not found
I am working from a Mac with OS Sonoma 14.6.1. I just updated R to version 4.4.1 and redownloaded Rcpp and RcppArmadillo. I have copied below a minimally-reproducible example that I found through Hadley Wickham's book:
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
NumericMatrix gibbs_cpp(int N, int thin) {
NumericMatrix mat(N, 2);
double x = 0, y = 0;
for(int i = 0; i < N; i++) {
for(int j = 0; j < thin; j++) {
x = rgamma(1, 3, 1 / (y * y + 4))[0];
y = rnorm(1, 1 / (x + 1), 1 / sqrt(2 * (x + 1)))[0];
}
mat(i, 0) = x;
mat(i, 1) = y;
}
return(mat);
}
If I save the above code in a file called text.cpp and source it using sourceCpp(test.cpp) I get the following error:
> sourceCpp("test.cpp")
using C++ compiler: ‘Apple clang version 16.0.0 (clang-1600.0.26.3)’
using SDK: ‘MacOSX15.0.sdk’
clang++ -arch arm64 -std=gnu++17 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/Rcpp/include" -I"/Users/ssamorod/Downloads" -I/opt/R/arm64/include -fPIC -falign-functions=64 -Wall -g -O2 -c test.cpp -o test.o
In file included from test.cpp:1:
In file included from /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/Rcpp/include/Rcpp.h:27:
In file included from /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/Rcpp/include/RcppCommon.h:30:
In file included from /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/Rcpp/include/Rcpp/r/headers.h:66:
/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/Rcpp/include/Rcpp/platform/compiler.h:100:10: fatal error: 'cmath' file not found
100 | #include <cmath>
| ^~~~~~~
1 error generated.
make: *** [test.o] Error 1
Error in sourceCpp("test.cpp") :
Error 1 occurred building shared library.
I wasn't able to find this specific error looking through previous Github issues and the listserv, but from similar ones I gathered it has something to do with my local machine, maybe with Xcode? I do not feel qualified to diagnose this myself since I'm very new to using Rcpp and C++. Hoping to get a bit of help or insight. Thank you in advance.
Sarah
Hi there,
I have a .cpp script I wrote several months ago that I haven't touched in a bit. I source that script using sourceCpp() in my R script. I am now getting the error:
fatal error: 'cmath' file not foundI am working from a Mac with OS Sonoma 14.6.1. I just updated R to version 4.4.1 and redownloaded Rcpp and RcppArmadillo. I have copied below a minimally-reproducible example that I found through Hadley Wickham's book:
If I save the above code in a file called
text.cppand source it usingsourceCpp(test.cpp)I get the following error:I wasn't able to find this specific error looking through previous Github issues and the listserv, but from similar ones I gathered it has something to do with my local machine, maybe with Xcode? I do not feel qualified to diagnose this myself since I'm very new to using Rcpp and C++. Hoping to get a bit of help or insight. Thank you in advance.
Sarah