Operating System: MacOS High Sierra
Interface Version: rstan 2.17.2
Compiler/Toolkit: clang/xcode
the downloaded rstan package can’t get compiler error messages from stanc.
I just upgraded to High Sierra (what’s in a name? celebrating legal pot in CA?).
In RStudio, I upgraded all installed packages - this gave me RStan 2.17.2.
Next I tried to compile a model with a simple syntax error:
Error in stanc(file = file, model_code = model_code, model_name = model_name, :
c++ exception (unknown reason)
the fix that worked for me is:
library(devtools)
this required a restart of the R session, then:
install.packages("rstan", type = "source")
Posting this for future reference - next I’ll check the RStan install page (because I don’t read the docs, I just write them).
didn’t read the docs, or see this message in Ben’s announcement:
The main change to rstan is that it should work with a Mac that uses the upstream version of clang (which CRAN now uses) rather than Xcode’s clang. It is necessary that the upstream clang be installed in /usr/local/clang4/bin/clang++. After that, there should be no more “unknown exception” messages.
because I don’t have clang4 installed at the prescribed path, I triggered this error. Will install clang4 and retest.
data exists, model compiles in cmdstan 2.17 - doesn’t run in R:
In file included from file16b41811ba3.cpp:8:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/src/stan/model/model_header.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/stan/math.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/stan/math/rev/mat.hp p:4:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/stan/math/rev/core.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/stan/math/rev/core/autodiffstackstorage.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/stan/math/memory/stack_alloc.hpp:8:
In file included from /usr/local/clang4/bin/…/include/c++/v1/cstdlib:86:
/usr/local/clang4/bin/…/include/c++/v1/stdlib.h:94:15: fatal error: ‘stdlib.h’ file not found #include_next <stdlib.h>
tried this - it didn’t work.
corrected syntactically incorrect file and tried again w/ command stan_model - this fails to link the generated .cpp file - same set of error messages as below for the funnel model.
still having fun - trying to use xcode clang++ compiler.
blew away my ~/.R/Makevars file, which was overwritten by the clang4 installer, and created the following Makevars file, per instructions on the RStan wiki for installs on Mac - current file is:
in a fresh RStudio session, try stan_model command for syntactially correct Stan program:
> stan_model("hello.stan")
In file included from file196e5bbee5d6.cpp:8:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/src/stan/model/model_header.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/stan/math.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/stan/math/rev/mat.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/stan/math/rev/core.hpp:12:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/stan/math/rev/core/gevv_vvv_vari.hpp:5:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/stan/math/rev/core/var.hpp:7:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/BH/include/boost/math/tools/config.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/BH/include/boost/config.hpp:39:
/Library/Frameworks/R.framework/Versions/3.4/Resources/library/BH/include/boost/config/compiler/clang.hpp:200:11: warning: 'BOOST_NO_CXX11_RVALUE_REFERENCES' macro redefined [-Wmacro-redefined]
# define BOOST_NO_CXX11_RVALUE_REFERENCES
^
<command line>:6:9: note: previous definition is here
#define BOOST_NO_CXX11_RVALUE_REFERENCES 1
^
1 warning generated.
giving the clang4 install another go, but still seeing problems trying to run a simple valid model through stan_model - linker fails with message:
/usr/local/clang4/bin/…/include/c++/v1/stdlib.h:94:15: fatal error: ‘stdlib.h’ file not found
similar to what was discussed in this thread:
I suspect the Makevars file created by that installer is missing stuff needed by rstan et al, but reading the R docs and that other thread I can’t figure out what those should be.
For what it may be worth, last week I was also having problems with RStan 2.17 swallowing parser warnings but I was able to get everything working using the vanilla Xcode toolkit (OS X 10.12.6, Xcode 9.2, Apple LLVM version 9.0.0 (clang-900.0.39.2)) by installing StanHeaders from source and then RStanArm 2.17.2 from source.
the problem remains that RStan users won’t see parser error messages without doing some kind of install from source and previously this wasn’t necessary, so existing users who upgrade will hit this error as well as any new users.
I’ve just done a pass as editing the RStan Wiki page: “Installing RStan on Mac or Linux”, but I didn’t just flat out say “you’re going to have to install from source” because maybe that’s too strong?
I did, however, update the section on crafting your Makevars file to the set of flags that seem to be necessary for make RStan compile without throwing lots of warnings.
Sorry, autocomplete typo – I meant StanHeaders and then RStan. No RStanArm. One issue I noticed is that if you install RStan from source then there’s a clash with StanHeaders which is precompiled presumably using a different version of clang. Compiling both from source ensures that everything is compiled with the same toolkit.
I stumbled into this the other day (maybe my OS X Mojave installation did something?) After Mojave installation I downloaded newest XCode, and ran Coatless’ installer. I changed my Makevars from the Coatless’ installer default to this: