Max Lau
Max Lau

Reputation: 31

math.h not found when using openmp (llvm) with sourceCpp

I am trying to use openmp in my Rcpp code and encounter some issues (Mac OS). Have tried googling a lot but not able to find a solution that works for me. Would appreciate if you can provide some thoughts.

Some of my setups: 1) installed llvm from home-brew 2) Makevars in ~/.R

CXX= /usr/local/opt/llvm/bin/clang-cpp

CXXFLAGS =-I/usr/local/lib -I/usr/local/opt/llvm/include

LDFLAGS=“-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib”

It looks like the LDFLAGS specified in the Makevars was ignored. Also, when I use sourceCpp(temp.cpp), I get this error

usr/local/opt/llvm/bin/clang-cpp -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Users/myname/Library/R/3.2/library/Rcpp/include" -I"/Users/myname/Library/R/3.2/library/RcppArmadillo/include" -fopenmp -fPIC -I/usr/local/lib -I/usr/local/opt/llvm/include -c temp.cpp -o temp.o

In file included from temp.cpp:2: /usr/local/Cellar/llvm/4.0.0_1/bin/../include/c++/v1/math.h:301:15: fatal error: 'math.h' file not found

include_next

^~~~~~~~ 1 error generated. Error in sourceCpp(paste(path2, "temp.cpp", sep = ""), verbose = TRUE, :
Error 1 occurred building shared library. make: *** [temp.o] Error 1

In the temp.cpp, I have put

#include <math.h>
#include <RcppArmadillo.h>
#include <omp.h>

// [[Rcpp::depends(RcppArmadillo)]]

// [[Rcpp::plugins(openmp)]]



using namespace Rcpp;

Upvotes: 3

Views: 1848

Answers (3)

user1995
user1995

Reputation: 538

For macOS, the best solution is to simply update your R version. Recent versions of R (>3.6) have resolved this issue.

See the discussion here - https://github.com/RcppCore/Rcpp/issues/922

Upvotes: 0

Terence Yang
Terence Yang

Reputation: 648

fro macos user, update the xcode and install it, then install the devtools , it works for me.

this is indicating that the dplyr package headers couldn't be found. I just tried from source and everything works. From the armadillo issue ticket, I think one problem is not using the CRAN-provided clang and setting the appropriate path. c.f. Installing the clang7 r binary

https://github.com/rmacoslib/r-macos-clang/issues/10

https://thecoatlessprofessor.com/programming/cpp/r-compiler-tools-for-rcpp-on-macos/

Upvotes: 0

G. Sharer
G. Sharer

Reputation: 21

Do you have Xcode command line tools installed (or re-installed after upgrading the operating system)? Try running:

xcode-select --install

This was the solution to a similar problem that I encountered recently.

Upvotes: 2

Related Questions