Rstan 2.18 compile error

System information

  • macOS 10.12.6
  • RStan 2.18.1
  • makevar
CXXFLAGS=-O3 -std=c++1y -mtune=native -march=native -Wno-unused-variable -Wno-unused-function

CC=clang
CXX=clang++ -arch x86_64 -ftemplate-depth-256
  • Output of devtools::session_info("rstan")
Error: `pkgs` 'rstan' are not installed

Error msg from install.packages("rstan")

clang++ -std=gnu++14 -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I"../inst/include" -I"`"/Library/Frameworks/R.framework/Resources/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"`" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/RcppEigen/include" -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include" -I/usr/local/include   -fPIC  -Wall -g -O2 -c lang__ast_def.cpp -o lang__ast_def.o
In file included from lang__ast_def.cpp:18:
/Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include/src/stan/lang/ast_def.cpp:738:30: error: 
      no matching constructor for initialization of 'printable_t' (aka
      'variant<recursive_wrapper<basic_string<char, char_traits<char>, allocator<char> > >,
      recursive_wrapper<stan::lang::expression> >')
    printable::printable() : printable_("") { }

You need to have CXX14FLAGS and CXX14 set like CXXFLAGS and CXX in your ~/.R/Makevars .

The same error with

CXXFLAGS=-O3 -std=c++1y -mtune=native -march=native -Wno-unused-variable -Wno-unused-function

CC=clang
CXX=clang++ -arch x86_64 -ftemplate-depth-256

CXX14=clang++ -arch x86_64 -ftemplate-depth-256 
CXX14FLAGS=-O3 -std=c++1y -mtune=native -march=native -Wno-unused-variable -Wno-unused-function

EDIT: I thought for macOS CXX14 will be set by installation process.

What is your clang++ version? The R installer for Mac does not set CXX14 but the recommended toolchain installer does.

bash-3.2$ clang++ --version
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin16.7.0
Thread model: posix

Do you have any idea why it refers to something at StanHeaders/include/src/stan/lang/ast_def.cpp:738:30 which only has 122 lines?

That’s confusing me tool. All the files in the include are of wrong version. Let me dig into my git setting.

Did you install StanHeaders from CRAN or from GitHub?

From github.

OK, try install.packages("StanHeaders") to get it from CRAN.

that solves it. I must have pull a wrong branch. Thanks.