Skip to content

Source Cpp file failed due to math.h not found #922

Closed
@yangleicq

Description

@yangleicq

Recently, I updated my mac to macOS Mojave Version (10.14.1). After that Rcpp cannot build from source. For the example below, "example.cpp" is just the template code created by Rstudio.

Rcpp::sourceCpp('Documents/example.cpp')
In file included from example.cpp:1:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include/Rcpp.h:27:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include/RcppCommon.h:29:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include/Rcpp/r/headers.h:59:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include/Rcpp/platform/compiler.h:100:
In file included from /usr/local/clang4/bin/../include/c++/v1/cmath:305:
/usr/local/clang4/bin/../include/c++/v1/math.h:301:15: fatal error: 'math.h' file not found
#include_next <math.h>
              ^~~~~~~~
1 error generated.
make: *** [example.o] Error 1
/usr/local/clang4/bin/clang++ -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I"/Users/yangleicq/Documents/" -I/usr/local/include   -fPIC  -Wall -g -O2  -c example.cpp -o example.o
Error in Rcpp::sourceCpp("Documents/example.cpp") : 
  Error 1 occurred building shared library.

I check the "/usr/local/clang4/bin/../include/c++/v1/math.h", it definitely is there.
I read the issue from coatless-mac/r-macos-clang#10 (comment), and followed the instruction to run xcode-select --install and sudo xcodebuild -license accept, still ran into the same error message. I reinstalled R, Rcpp, Xcode, still the the same error message.

Finally I changed CXX=/usr/local/clang4/bin/clang++ to CXX=g++ in ~/.R/Makevars, and the error message is gone. Basically I can only change the compiler to make things work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions