Rstan installation / compilation fails on Debian

doing install.packages(“rstan”) on R

R version 4.0.2 (2020-06-22) -- "Taking Off Again"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

on a Debian box with recent packages, esp. using:

g++:
  Installed: 4:9.2.1-3.1
  Candidate: 4:9.2.1-3.1
  Version table:
     4:10-1 102
        102 http://httpredir.debian.org/debian experimental/main amd64 Packages
 *** 4:9.2.1-3.1 750
        750 http://httpredir.debian.org/debian testing/main amd64 Packages
        500 http://httpredir.debian.org/debian unstable/main amd64 Packages
        100 /var/lib/dpkg/status

Installation aborts with:

Detailed error message from g++...
n file included from stan/lang/ast_def.cpp:97:
./stan/lang/ast/sigs/function_signatures_def.hpp: In constructor ‘stan::lang::function_signatures::function_signatures()’:
./stan/lang/ast/sigs/function_signatures_def.hpp:474:1: note: variable tracking size limit exceeded with ‘-fvar-tracking-assignments’, retrying without
  474 | function_signatures::function_signatures() {
      | ^~~~~~~~~~~~~~~~~~~
g++ -std=gnu++14 -I"/usr/share/R/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'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/RcppEigen/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/BH/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/StanHeaders/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/RcppParallel/include'    -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-OT058M/r-base-4.0.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c stan/lang/grammars/program_grammar_inst.cpp -o stan/lang/grammars/program_grammar_inst.o
g++ -std=gnu++14 -I"/usr/share/R/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'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/RcppEigen/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/BH/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/StanHeaders/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/RcppParallel/include'    -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-OT058M/r-base-4.0.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c stan/lang/grammars/expression_grammar_inst.cpp -o stan/lang/grammars/expression_grammar_inst.o
g++ -std=gnu++14 -I"/usr/share/R/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'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/RcppEigen/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/BH/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/StanHeaders/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/RcppParallel/include'    -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-OT058M/r-base-4.0.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c stan/lang/grammars/statement_grammar_inst.cpp -o stan/lang/grammars/statement_grammar_inst.o
g++ -std=gnu++14 -I"/usr/share/R/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'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/RcppEigen/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/BH/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/StanHeaders/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/RcppParallel/include'    -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-OT058M/r-base-4.0.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c stan/lang/grammars/expression07_grammar_inst.cpp -o stan/lang/grammars/expression07_grammar_inst.o
g++ -std=gnu++14 -I"/usr/share/R/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'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/RcppEigen/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/BH/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/StanHeaders/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/RcppParallel/include'    -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-OT058M/r-base-4.0.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c stan/lang/grammars/statement_2_grammar_inst.cpp -o stan/lang/grammars/statement_2_grammar_inst.o
g++ -std=gnu++14 -I"/usr/share/R/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'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/RcppEigen/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/BH/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/StanHeaders/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/RcppParallel/include'    -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-OT058M/r-base-4.0.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c stan/lang/grammars/block_var_decls_grammar_inst.cpp -o stan/lang/grammars/block_var_decls_grammar_inst.o
g++ -std=gnu++14 -I"/usr/share/R/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'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/RcppEigen/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/BH/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/StanHeaders/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/RcppParallel/include'    -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-OT058M/r-base-4.0.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c stan/lang/grammars/term_grammar_inst.cpp -o stan/lang/grammars/term_grammar_inst.o
g++ -std=gnu++14 -I"/usr/share/R/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'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/RcppEigen/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/BH/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/StanHeaders/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/RcppParallel/include'    -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-OT058M/r-base-4.0.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c stan/lang/grammars/indexes_grammar_inst.cpp -o stan/lang/grammars/indexes_grammar_inst.o
g++ -std=gnu++14 -I"/usr/share/R/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'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/RcppEigen/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/BH/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/StanHeaders/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/RcppParallel/include'    -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-OT058M/r-base-4.0.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c stan/lang/grammars/semantic_actions_def.cpp -o stan/lang/grammars/semantic_actions_def.o
g++ -std=gnu++14 -I"/usr/share/R/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'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/RcppEigen/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/BH/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/StanHeaders/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/RcppParallel/include'    -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-OT058M/r-base-4.0.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c stan/lang/grammars/whitespace_grammar_inst.cpp -o stan/lang/grammars/whitespace_grammar_inst.o
g++ -std=gnu++14 -I"/usr/share/R/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'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/RcppEigen/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/BH/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/StanHeaders/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/RcppParallel/include'    -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-OT058M/r-base-4.0.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c stan/lang/grammars/bare_type_grammar_inst.cpp -o stan/lang/grammars/bare_type_grammar_inst.o
g++ -std=gnu++14 -I"/usr/share/R/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'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/RcppEigen/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/BH/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/StanHeaders/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/RcppParallel/include'    -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-OT058M/r-base-4.0.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c stan/lang/grammars/local_var_decls_grammar_inst.cpp -o stan/lang/grammars/local_var_decls_grammar_inst.o
g++ -std=gnu++14 -I"/usr/share/R/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'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/RcppEigen/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/BH/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/StanHeaders/include' -I'/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/RcppParallel/include'    -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-OT058M/r-base-4.0.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c stan/lang/grammars/functions_grammar_inst.cpp -o stan/lang/grammars/functions_grammar_inst.o
g++ -std=gnu++14 -shared -L/usr/lib/R/lib -Wl,-z,relro -o rstan.so chains.o pointer-tools.o stan_fit_base.o stanc.o Module.o stan_fit_rccp.o misc.o sparse_extractors.o init.o stan/lang/ast_def.o stan/lang/grammars/program_grammar_inst.o stan/lang/grammars/expression_grammar_inst.o stan/lang/grammars/statement_grammar_inst.o stan/lang/grammars/expression07_grammar_inst.o stan/lang/grammars/statement_2_grammar_inst.o stan/lang/grammars/block_var_decls_grammar_inst.o stan/lang/grammars/term_grammar_inst.o stan/lang/grammars/indexes_grammar_inst.o stan/lang/grammars/semantic_actions_def.o stan/lang/grammars/whitespace_grammar_inst.o stan/lang/grammars/bare_type_grammar_inst.o stan/lang/grammars/local_var_decls_grammar_inst.o stan/lang/grammars/functions_grammar_inst.o -L/usr/lib/R/lib -lR
collect2: error: ld returned 1 exit status
make: *** [/usr/share/R/share/make/shlib.mk:6: rstan.so] Error 1
ERROR: compilation failed for package ‘rstan’
* removing ‘/home/dlakelan/R/x86_64-pc-linux-gnu-library/4.0/rstan’

Is this me doing something wrong, like using an incompatible version of R or g++ or needing to install some development packages, or do I need to file a bug?

Is there more output associated with that linker error?

Unfortunately no :-\

I would guess it is failing to link against the TBB shared object. But that should be handled by the Makevars file

So I don’t know why that wouldn’t be reflected in the linker call.

Where is this Makevars file installed?

Nowhere. It is just in the rstan source and governs the installation.

Does tbb need to be installed at system level or is it included in rstan?

In any case, updating / installing libtbb-dev didn’t help any.

It appears that this has something to do with running out of temporary space on my /tmp partition (which is a 1GB RAM disk). By exporting TMPDIR=/var/tmp (which is a big spinning platter) the install completed. Apparently installing rstan may require more than ~1GB of temporary storage.

The TBB in the RcppParallel package is the one we are targeting but a sufficiently recent system version may work. My guess is that if it is taking 1GB of temporary space on your machine that it is generating debug symbols or using pipes or something that is set in the system Makefiles for R