Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
yangleicq opened this issue Nov 15, 2018 · 7 comments
Closed

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

yangleicq opened this issue Nov 15, 2018 · 7 comments

Comments

@yangleicq
Copy link

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.

@coatless
Copy link
Contributor

coatless commented Nov 15, 2018

@yangleicq c.f. coatless-mac/r-macos-rtools#11 (comment)

On Mojave use:

sudo installer -pkg \
/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg \
-target /

@eddelbuettel please close.

@yangleicq
Copy link
Author

Thank you, it works.

@kklot
Copy link

kklot commented Mar 28, 2019

Does not work for me, installed

installer: Package name is macOS_SDK_headers_for_macOS_10.14
installer: Installing at base path /
installer: The install was successful.

restarted R, restarted Mac

/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include/Rcpp/platform/compiler.h:100:10: fatal error: 'cmath' file not found

@eddelbuettel
Copy link
Member

So your ducks are not in a row. See the Rcpp FAQ vignette. Ask for help on r-sig-mac. It works for CRAN on macOS too, as it does for thousands of users.

dpc10ster added a commit to dpc10ster/RJafroc that referenced this issue May 23, 2019
RcppCore/Rcpp#922
xcode-select --install
sudo installer -pkg \
/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg \
-target /
@glennmschultz
Copy link

Running into the same problem on Catalina OS. Does the recommend fix for Mojave work as well just replace the build number?

@eddelbuettel
Copy link
Member

Not a macOS user myself but there were a number of posts on StackOverflow too once Catalina was released. As I recall, you need to reinstall some tools. This thread is not the best reference so I recommend we do not continue here.

@kevinushey
Copy link
Contributor

Unfortunately, those instructions are no longer relevant for macOS Catalona. See the guide @coatless has put together:

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

Note also that the issue is handled by R itself in the recent patch releases of R 3.6.1 as well. If you're aggressively updating your OS, you should be aggressively updating your other software as well.

Locking this thread for now as it is indeed not the best avenue for discussion.

@RcppCore RcppCore locked as resolved and limited conversation to collaborators Nov 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants