Error in rstan

Does anyone know what does this error mean?

Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! clang: warning: no such sysroot directory: '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk' [-Wmissing-sysroot]
In file included from file4c61ad8d4a6.cpp:8:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/src/stan/model/model_header.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/stan/math.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/stan/math/rev/mat.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/stan/math/rev/core.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/stan/math/rev/core/autodiffstackstorage.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/in
In addition: Warning message:
In system(cmd, intern = !verbose) :
  running command '/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file4c61ad8d4a6.cpp 2> file4c61ad8d4a6.cpp.err.txt' had status 1
Error in sink(type = "output") : invalid connection

Need to run it with verbose = TRUE to be sure but the

clang: warning: no such sysroot directory: ‘/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk’

suggests that it is not going to be able to find the system headers. Have you recently upgraded to Catalina?

yesterday i upgraded.so now?

It doesn’t work. Are you using clang++ from Xcode or from CRAN and if so, what version?

i am using Xcode version 11.0.

Unfortunately same issue. I have tried running the solutions offered including:

  • Coatless process
  • installing latest Clang from CRAN
  • fix_Mac on the model --> fix_Mac( rstan::stan_model(“103_VBGF.stan”))

One of my projects still runs (CJS model), but I am not sure what is happening under the hood with any of this…

Is there light here at the end of the tunnel? Is there scope for one of the senior people here to give a bullet point update for us in academia who aren’t developers?

Thank you.
Steve

1 Like
  • Things are broken on Catalina
  • The fix that we used in 2017 (and then were led to believe would be unnecessary) does not seem to work 100% of the time nowdays
  • We want to upload a Rstan shortly after Stan 2.21 is released Friday
  • We need more information as to when fix_Mac does and does not work for models that throw exceptions.

As I had the automatic update force me onto Catalina 10.15 and I still have those work deadlines. Since I can’t work out how to go back to Mojave, is there an ETA on when RStan on MacOS is back to normal?

We don’t fully understand the issue yet. Does


work on your case?

As a last resort, if CmdStan doesn’t have problems with Catalina (I would think more it’s likely to be ok than RStan) then you could try out the new (unreleased, and unannounced until now, and subject to change) CmdStanR interface, which can be installed from GitHub

devtools::install_github("stan-dev/cmdstanr")

There’s a brief intro vignette showing how to install cmdstan (there’s an install_cmdstan function) and then use cmdstanr to fit models from R (and obtain a stanfit object from the results if you want):

https://mc-stan.org/cmdstanr/articles/cmdstanr.html

The one important feature it’s currently missing is the ability to run chains in parallel, although you could wrap it in a call to mclapply (or something like that).

1 Like

I cannot get brms to even make an object to apply it to.

OK. That is a different problem then. What does

library(rstan)
example(stan_model, run.dontrun = TRUE)

output on the line that has error: in it (with the colon)?

I get this:

Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! In file included from file5cb159435b8.cpp:8:
In file included from /Users/lukemansillo/Library/R/3.6/library/StanHeaders/include/src/stan/model/model_header.hpp:4:
In file included from /Users/lukemansillo/Library/R/3.6/library/StanHeaders/include/stan/math.hpp:4:
In file included from /Users/lukemansillo/Library/R/3.6/library/StanHeaders/include/stan/math/rev/mat.hpp:4:
In file included from /Users/lukemansillo/Library/R/3.6/library/StanHeaders/include/stan/math/rev/core.hpp:5:
In file included from /Users/lukemansillo/Library/R/3.6/library/StanHeaders/include/stan/math/rev/core/build_vari_array.hpp:4:
In file included from /Users/lukemansillo/Library/R/3.6/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/RcppEigen/include/Eigen/Dense:1:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/Rc

So I suspect this

was not what you were after when you said this:

I’m not feeling like the sharpest tool in the shed at the moment so please bear with me (and you have my utter thanks).

Yesterday I was getting these errors then did something to Makevars and when I tried to run a model in brms the errors were the same as this:

I tried to reinstall rstan and then the error I am querying reappeared.

My workflow is mostly in brms now so I am at a bit of a loss about how the fix_Mac function could work.

Is there anything I do to help?

When you do

example(stan_model, run.dontrun = TRUE)

there should be about 500 lines of C++ code, which you can ignore, followed by a line that starts like

clang++ ...

followed by an indeterminate amount of warnings, which you can ignore, followed by a line that has

error:

in it. I’m guessing it will say that some file is not found. We’ll be able to fit that, in which case you’ll be back to the “c++ exception (unknown reason)” error when you run models that the fix_Mac function was intended to fix. But it doesn’t actually fix the problem when there are any other packages that load C++ code, including ggplot2, which is loaded by rstan. Hopefully, we’ll come up with something better by Friday with Stan 2.21 is released.

I had a go at installing RcppArmadillo from source. I don’t know where my apple complier has gone.

install.packages("RcppArmadillo", type = "source")
Installing package into ‘/Users/lukemansillo/Library/R/3.6/library’
(as ‘lib’ is unspecified)
trying URL 'http://cran.rstudio.com/src/contrib/RcppArmadillo_0.9.800.1.0.tar.gz'
Content type 'application/x-gzip' length 1372832 bytes (1.3 MB)
==================================================
downloaded 1.3 MB

* installing *source* package ‘RcppArmadillo’ ...
** package ‘RcppArmadillo’ successfully unpacked and MD5 sums checked
** using staged installation
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether clang++ -std=gnu++11 accepts -g... yes
checking how to run the C++ preprocessor... clang++ -std=gnu++11 -E
checking whether we are using the GNU C++ compiler... (cached) yes
checking whether clang++ -std=gnu++11 accepts -g... (cached) yes
checking whether g++ version is sufficient... almost
configure: WARNING: Compiler self-identifies as being compliant with GNUC extensions but is not g++.
checking for macOS... found
checking for macOS Apple compiler... not found
checking for clang compiler... found
checking for OpenMP compatible version of clang... found and suitable
checking LAPACK_LIBS... R-supplied partial LAPACK found
configure: WARNING: Some complex-valued LAPACK functions may not be available
checking for OpenMP... found and suitable
configure: creating ./config.status
config.status: creating inst/include/RcppArmadilloConfigGenerated.h
config.status: creating src/Makevars
** libs
clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I"/Users/lukemansillo/Library/R/3.6/library/Rcpp/include/"  -I"/Library/Frameworks/R.framework/Versions/3.6/Resources/library/RcppEigen/include/"  -I"/Library/Frameworks/R.framework/Versions/3.6/Resources/library/RcppEigen/include/unsupported"  -I"/Library/Frameworks/R.framework/Versions/3.6/Resources/library/BH/include" -I"/Users/lukemansillo/Library/R/3.6/library/StanHeaders/include/src/"  -I"/Users/lukemansillo/Library/R/3.6/library/StanHeaders/include/"  -I"/Users/lukemansillo/Library/R/3.6/library/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS -I"/Users/lukemansillo/Library/R/3.6/library/Rcpp/include" -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -I../inst/include -fopenmp -fPIC  -Wall -g -O2  -c RcppArmadillo.cpp -o RcppArmadillo.o
In file included from RcppArmadillo.cpp:22:
In file included from ../inst/include/RcppArmadillo.h:31:
In file included from ../inst/include/RcppArmadilloForward.h:26:
In file included from /Users/lukemansillo/Library/R/3.6/library/Rcpp/include/RcppCommon.h:29:
In file included from /Users/lukemansillo/Library/R/3.6/library/Rcpp/include/Rcpp/r/headers.h:59:
In file included from /Users/lukemansillo/Library/R/3.6/library/Rcpp/include/Rcpp/platform/compiler.h:100:
/usr/local/clang7/include/c++/v1/cmath:313:9: error: no member named 'signbit' in the global namespace
using ::signbit;
      ~~^
/usr/local/clang7/include/c++/v1/cmath:314:9: error: no member named 'fpclassify' in the global namespace
using ::fpclassify;
      ~~^
/usr/local/clang7/include/c++/v1/cmath:315: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 RcppArmadillo.cpp:22:
In file included from ../inst/include/RcppArmadillo.h:31:
In file included from ../inst/include/RcppArmadilloForward.h:26:
In file included from /Users/lukemansillo/Library/R/3.6/library/Rcpp/include/RcppCommon.h:29:
In file included from /Users/lukemansillo/Library/R/3.6/library/Rcpp/include/Rcpp/r/headers.h:59:
In file included from /Users/lukemansillo/Library/R/3.6/library/Rcpp/include/Rcpp/platform/compiler.h:100:
/usr/local/clang7/include/c++/v1/cmath:316:9: error: no member named 'isinf' in the global namespace
using ::isinf;
      ~~^
/usr/local/clang7/include/c++/v1/cmath:317:9: error: no member named 'isnan' in the global namespace
using ::isnan;
      ~~^
/usr/local/clang7/include/c++/v1/cmath:318:9: error: no member named 'isnormal' in the global namespace
using ::isnormal;
      ~~^
/usr/local/clang7/include/c++/v1/cmath:319:9: error: no member named 'isgreater' in the global namespace
using ::isgreater;
      ~~^
/usr/local/clang7/include/c++/v1/cmath:320:9: error: no member named 'isgreaterequal' in the global namespace
using ::isgreaterequal;
      ~~^
/usr/local/clang7/include/c++/v1/cmath:321:9: error: no member named 'isless' in the global namespace
using ::isless;
      ~~^
/usr/local/clang7/include/c++/v1/cmath:322:9: error: no member named 'islessequal' in the global namespace
using ::islessequal;
      ~~^
/usr/local/clang7/include/c++/v1/cmath:323:9: error: no member named 'islessgreater' in the global namespace
using ::islessgreater;
      ~~^
/usr/local/clang7/include/c++/v1/cmath:324:9: error: no member named 'isunordered' in the global namespace
using ::isunordered;
      ~~^
/usr/local/clang7/include/c++/v1/cmath:325:9: error: no member named 'isunordered' in the global namespace
using ::isunordered;
      ~~^
/usr/local/clang7/include/c++/v1/cmath:331: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 RcppArmadillo.cpp:22:
In file included from ../inst/include/RcppArmadillo.h:31:
In file included from ../inst/include/RcppArmadilloForward.h:26:
In file included from /Users/lukemansillo/Library/R/3.6/library/Rcpp/include/RcppCommon.h:29:
In file included from /Users/lukemansillo/Library/R/3.6/library/Rcpp/include/Rcpp/r/headers.h:59:
In file included from /Users/lukemansillo/Library/R/3.6/library/Rcpp/include/Rcpp/platform/compiler.h:100:
/usr/local/clang7/include/c++/v1/cmath:551:28: error: expected a qualified name after 'typename'
_LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type
                           ^
/usr/local/clang7/include/c++/v1/cmath:551:37: error: expected ';' at end of declaration
_LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type
                                    ^
/usr/local/clang7/include/c++/v1/cmath:551:37: error: expected unqualified-id
/usr/local/clang7/include/c++/v1/cmath:563:39: error: use of undeclared identifier 'is_floating_point'
_LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type
                                      ^
/usr/local/clang7/include/c++/v1/cmath:563:57: error: '_A1' does not refer to a value
_LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type
                                                        ^
/usr/local/clang7/include/c++/v1/cmath:561:17: note: declared here
template <class _A1>
                ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [RcppArmadillo.o] Error 1
ERROR: compilation failed for package ‘RcppArmadillo’
* removing ‘/Users/lukemansillo/Library/R/3.6/library/RcppArmadillo’
* restoring previous ‘/Users/lukemansillo/Library/R/3.6/library/RcppArmadillo’
Warning in install.packages :
  installation of package ‘RcppArmadillo’ had non-zero exit status

The downloaded source packages are in
	‘/private/var/folders/bx/8ltnl1nd13b3k8vjzl8m7ffw0000gn/T/RtmpxsWFpb/downloaded_packages’

some sections which I suspect are related to my last post

In file included from /usr/local/clang7/include/c++/v1/complex:246:
/usr/local/clang7/include/c++/v1/cmath:313:9: error: no member named 'signbit' in the global namespace
using ::signbit;
      ~~^
/usr/local/clang7/include/c++/v1/cmath:314:9: error: no member named 'fpclassify' in the global namespace
using ::fpclassify;
      ~~^
/usr/local/clang7/include/c++/v1/cmath:315: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)
           ^

and

In file included from /usr/local/clang7/include/c++/v1/complex:246:
/usr/local/clang7/include/c++/v1/cmath:316:9: error: no member named 'isinf' in the global namespace
using ::isinf;
      ~~^
/usr/local/clang7/include/c++/v1/cmath:317:9: error: no member named 'isnan' in the global namespace
using ::isnan;
      ~~^
/usr/local/clang7/include/c++/v1/cmath:318:9: error: no member named 'isnormal' in the global namespace
using ::isnormal;
      ~~^
/usr/local/clang7/include/c++/v1/cmath:319:7: error: no member named 'isgreater' in the global namespace; did you mean '::std::greater'?
using ::isgreater;
      ^~

and

/usr/local/clang7/include/c++/v1/cmath:320:7: error: no member named 'isgreaterequal' in the global namespace; did you mean '::std::greater_equal'?
using ::isgreaterequal;
      ^~

and

In file included from /usr/local/clang7/include/c++/v1/complex:246:
/usr/local/clang7/include/c++/v1/cmath:321:9: error: no member named 'isless' in the global namespace
using ::isless;
      ~~^
/usr/local/clang7/include/c++/v1/cmath:322:9: error: no member named 'islessequal' in the global namespace
using ::islessequal;
      ~~^
/usr/local/clang7/include/c++/v1/cmath:323:9: error: no member named 'islessgreater' in the global namespace
using ::islessgreater;
      ~~^
/usr/local/clang7/include/c++/v1/cmath:324:9: error: no member named 'isunordered' in the global namespace
using ::isunordered;
      ~~^
/usr/local/clang7/include/c++/v1/cmath:325:9: error: no member named 'isunordered' in the global namespace
using ::isunordered;
      ~~^

and

/Library/Frameworks/R.framework/Versions/3.6/Resources/library/RcppEigen/include/Eigen/src/Core/MathFunctions.h:712:16: error: no member named 'isfinite' in namespace 'std'; did you mean 'finite'?
    using std::isfinite;
          ~~~~~^~~~~~~~
               finite
/usr/local/clang7/include/c++/v1/cmath:315:9: note: 'finite' declared here
using ::isfinite;
        ^

and

/Library/Frameworks/R.framework/Versions/3.6/Resources/library/RcppEigen/include/Eigen/src/Core/MathFunctions.h:727:16: error: no member named 'isinf' in namespace 'std'
    using std::isinf;
          ~~~~~^
/Library/Frameworks/R.framework/Versions/3.6/Resources/library/RcppEigen/include/Eigen/src/Core/MathFunctions.h:742:16: error: no member named 'isnan' in namespace 'std'
    using std::isnan;
          ~~~~~^

and

/Users/lukemansillo/Library/R/3.6/library/StanHeaders/include/stan/math/prim/scal/fun/is_nan.hpp:17:44: error: expected unqualified-id
inline bool is_nan(double x) { return std::isnan(x); }
                                           ^
/usr/local/include/math.h:165:5: note: expanded from macro 'isnan'
    ( sizeof(x) == sizeof(float)  ? __inline_isnanf((float)(x))          \
    ^

and

/Library/Frameworks/R.framework/Versions/3.6/Resources/library/BH/include/boost/math/special_functions/sign.hpp:30:17: error: no member named 'signbit' in namespace 'std'; did you mean simply 'signbit'?
        return (std::signbit)(x) ? 1 : 0;
                ^~~~~~~~~~~~
                signbit

and

/Library/Frameworks/R.framework/Versions/3.6/Resources/library/BH/include/boost/math/special_functions/fpclassify.hpp:155:12: error: no member named 'fpclassify' in namespace 'std'; did you mean simply 'fpclassify'?
   return (std::fpclassify)(t);
           ^~~~~~~~~~~~~~~
           fpclassify
/Library/Frameworks/R.framework/Versions/3.6/Resources/library/BH/include/boost/math/special_functions/math_fwd.hpp:876:8: note: 'fpclassify' declared here
   int fpclassify BOOST_NO_MACRO_EXPAND(T t);
       ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
8 warnings and 20 errors generated.
make: *** [file1f4297d521.o] Error 1

I’m inclined to agree, there are too many errors emitted.

Well, it is pretty much the same error over and over again. Did you manage to get through all the steps from
https://thecoatlessprofessor.com/programming/cpp/r-compiler-tools-for-rcpp-on-macos/
?

I am pretty sure I did … to be use I’m going to reinstall xcode and go through all the steps.

I’ve got xcode CLT …

lukemansillo@Luke-Mansillo-MacBook-Pro ~ % gcc --version

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1

Apple clang version 11.0.0 (clang-1100.0.33.8)

Target: x86_64-apple-darwin19.0.0

Thread model: posix

InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Then installed both clang7 and gfortran6.1 binaries.

Yet the helloworld.cpp file does this: