stan-dev / rstan

RStan, the R interface to Stan
https://mc-stan.org
1.04k stars 269 forks source link

Install Error - macOS Big Sur #904

Open leoguelman opened 3 years ago

leoguelman commented 3 years ago

Getting the error message below during installation. Any hints would be appreciated.

> Sys.setenv(DOWNLOAD_STATIC_LIBV8 = 1) # only necessary for Linux without the nodejs library / headers
> install.packages("rstan", repos = "https://cloud.r-project.org/", dependencies = TRUE)

  There is a binary version available but the source version is later:
      binary source needs_compilation
rstan 2.21.1 2.21.2              TRUE

Do you want to install from sources the package which needs compilation? (Yes/no/cancel) yes
installing the source package ‘rstan’

trying URL 'https://cloud.r-project.org/src/contrib/rstan_2.21.2.tar.gz'
Content type 'application/x-gzip' length 1152008 bytes (1.1 MB)
==================================================
downloaded 1.1 MB

* installing *source* package ‘rstan’ ...
** package ‘rstan’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
clang++ -mmacosx-version-min=10.13 -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"../inst/include" -I"../inst/include/boost_not_in_BH" -I"." -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -DBOOST_NO_AUTO_PTR -D_REENTRANT -DSTAN_THREADS   -I'/Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include' -I'/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include' -I'/Library/Frameworks/R.framework/Versions/4.0/Resources/library/BH/include' -I'/Library/Frameworks/R.framework/Versions/4.0/Resources/library/StanHeaders/include' -I'/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppParallel/include' -I/usr/local/include   -fPIC  -Wall -g -O2  -O3 -mtune=native -arch x86_64 -ftemplate-depth-256 -c Module.cpp -o Module.o
In file included from Module.cpp:1:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include/Rcpp.h:27:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include/RcppCommon.h:29:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include/Rcpp/r/headers.h:67:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include/Rcpp/platform/compiler.h:100:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:317:9: error: no member named 'signbit' in the global namespace
using ::signbit;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:318:9: error: no member named 'fpclassify' in the global namespace
using ::fpclassify;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:319:9: error: no member named 'isfinite' in the global namespace; did you mean 'finite'?
using ::isfinite;
      ~~^
/usr/local/include/math.h:749:12: note: 'finite' declared here
extern int finite(double)
           ^
In file included from Module.cpp:1:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include/Rcpp.h:27:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include/RcppCommon.h:29:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include/Rcpp/r/headers.h:67:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include/Rcpp/platform/compiler.h:100:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:320:9: error: no member named 'isinf' in the global namespace
using ::isinf;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:321:9: error: no member named 'isnan' in the global namespace
using ::isnan;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:322:9: error: no member named 'isnormal' in the global namespace
using ::isnormal;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:323:9: error: no member named 'isgreater' in the global namespace
using ::isgreater;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:324:9: error: no member named 'isgreaterequal' in the global namespace
using ::isgreaterequal;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:325:9: error: no member named 'isless' in the global namespace
using ::isless;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:326:9: error: no member named 'islessequal' in the global namespace
using ::islessequal;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:327:9: error: no member named 'islessgreater' in the global namespace
using ::islessgreater;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:328:9: error: no member named 'isunordered' in the global namespace
using ::isunordered;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:329:9: error: no member named 'isunordered' in the global namespace
using ::isunordered;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:335:9: error: no member named 'abs' in the global namespace; did you mean 'fabs'?
using ::abs;
      ~~^
/usr/local/include/math.h:417:15: note: 'fabs' declared here
extern double fabs(double);
              ^
In file included from Module.cpp:1:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include/Rcpp.h:27:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include/RcppCommon.h:29:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include/Rcpp/r/headers.h:67:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include/Rcpp/platform/compiler.h:100:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:640:26: error: no template named 'numeric_limits'
    bool _FloatBigger = (numeric_limits<_FloatT>::digits > numeric_limits<_IntT>::digits),
                         ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:640:60: error: no template named 'numeric_limits'
    bool _FloatBigger = (numeric_limits<_FloatT>::digits > numeric_limits<_IntT>::digits),
                                                           ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:641:18: error: no template named 'numeric_limits'
    int _Bits = (numeric_limits<_IntT>::digits - numeric_limits<_FloatT>::digits)>
                 ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:641:50: error: no template named 'numeric_limits'
    int _Bits = (numeric_limits<_IntT>::digits - numeric_limits<_FloatT>::digits)>
                                                 ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:646:17: error: no template named 'numeric_limits'
  static_assert(numeric_limits<_FloatT>::radix == 2, "FloatT has incorrect radix");
                ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [Module.o] Error 1
ERROR: compilation failed for package ‘rstan’
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/rstan’

The downloaded source packages are in
    ‘/private/var/folders/kw/_5nyl9vx5pn29m885dzd3hkm0000gn/T/RtmpH7j3f0/downloaded_packages’
Warning message:
In install.packages("rstan", repos = "https://cloud.r-project.org/",  :
  installation of package ‘rstan’ had non-zero exit status
> 

RStan Version:

R version 4.0.3 (2020-10-10) Platform: x86_64-apple-darwin17.0 (64-bit) Running under: macOS Big Sur 10.16

Matrix products: default BLAS: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale: [1] en_CA.UTF-8/en_CA.UTF-8/en_CA.UTF-8/C/en_CA.UTF-8/en_CA.UTF-8

attached base packages: [1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached): [1] compiler_4.0.3 tools_4.0.3

jeffreypullin commented 3 years ago

I think the answers here:

https://stackoverflow.com/questions/58628377/catalina-c-using-cmath-headers-yield-error-no-member-named-signbit-in-th

may be helpful.

storopoli commented 3 years ago

I've tried following the answers from stack overflow and the only thing that solved was to run R as sudo.

sudo R

then:

install.packages(c("StanHeaders", "Stan"))

Please note that all subsequent models that you sample using rstan must be run from a sudo R session.

One way to get around this is to use cmdstanr. I compile the model using a sudo R session and then give permission to my user using sudo chown -R $(whoami) .cmdstanr.

If somebody knows how to deal with the damned <cmath> header problem in MacOS please let me know. All solutions from the stack overflow link was to no avail.

LeonardoGFernandes commented 3 years ago

did anyone have any luck? I am having the same problem after updating to Big Sur. I tried the suggested solutions and no luck.

My Configuration just in case: macOS Big Sur Version 11.2.3

R version 4.0.5 (2021-03-31)

GNU Fortran (GCC) 8.2.0

Apple clang version 12.0.0 (clang-1200.0.32.29) Target: x86_64-apple-darwin20.3.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

LeonardoGFernandes commented 3 years ago

@leoguelman In case you (or anyone else who is getting this error) have not yet solved it. What worked for me was uninstalling the command line tools >sudo rm -rf /Library/Developer/CommandLineTools and the Xcode app. I then re-installed the xcode app and did NOT install the command line tools > xcode-select --install . I think something in the app was getting overwritten when running the > xcode-select --install command as the command line tools are already pre-installed in the new versions of the xcode app.

vivid225 commented 3 years ago

@LeonardoGFernandes Thank you so much for the solution!!! I have the same configuration as yours. It took me six hours struggling in the installation error until I saw your post. One thing to add if anyone has the same situation: remember to run >xcode-select --switch path/to/Xcode.app in your terminal after installing Xcode app. I wasn't reading the warning message carefully so the path switching confused me for a while.

Again, thank you!!!

hrithiksagar commented 3 years ago

did anyone have any luck? I am having the same problem after updating to Big Sur. I tried the suggested solutions and no luck.

My Configuration just in case: macOS Big Sur Version 11.2.3

R version 4.0.5 (2021-03-31)

GNU Fortran (GCC) 8.2.0

Apple clang version 12.0.0 (clang-1200.0.32.29) Target: x86_64-apple-darwin20.3.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

i dont have xcode installed, as it was consuming around 30Gb of storage, i deleted it as i dont use it, but now whatever video/issue i read for installing "bits/stdc++.h" are solving via "> InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin" this directory, and this doesnt exists for me, what should i do?

RJVB commented 3 years ago

FWIW, Xcode contains a lot of stuff for iOS development, including a simulator. All that is cruddy bloatware if you don't use it, but it can be deleted. IIRC (I did this years ago) it takes a bit of trial and error as some paths must be present at startup, so just move the iOS-related things out of the Xcode app bundle so you can move them back easily, and experiment with creating empty directories for those that Xcode complains about. I got Xcode 6.2 down to 2.5Gb that way (1.1Gb with HFS+ compression).

daaronr commented 2 years ago

You may be able to work around this. https://thecoatlessprofessor.com/programming/cpp/r-compiler-tools-for-rcpp-on-macos/ guide worked for me