Error when running rstan with linux

Hello, I get this error when running stan:

library(rstan)
scode <- "
parameters {
   real y[2];
}
model {
  y[1] ~ normal(0, 1);
  y[2] ~ double_exponential(0, 2);
}
"
fit1 <- stan(model_code = scode, iter = 10, verbose = TRUE)
TRANSLATING MODEL '35830db9246beefe3363141b64f17491' FROM Stan CODE TO C++ CODE NOW.
successful in parsing the Stan model '35830db9246beefe3363141b64f17491'.
'config' variable 'CPP' is deprecated
gcc -std=gnu99 -E
COMPILING THE C++ CODE FOR MODEL '35830db9246beefe3363141b64f17491' NOW.
OS: x86_64, linux-gnu; rstan: 2.21.3; Rcpp: 1.0.5; inline: 0.3.16 
 >> setting environment variables: 
PKG_LIBS =  '/home/s/sdaza/R/x86_64-pc-linux-gnu-library/4.0/rstan/lib//libStanServices.a' -L'/home/s/sdaza/R/x86_64-pc-linux-gnu-library/4.0/StanHeaders/lib/' -lStanHeaders -L'/home/s/sdaza/R/x86_64-pc-linux-gnu-library/4.0/RcppParallel/lib/' -ltbb
PKG_CPPFLAGS =   -I"/home/s/sdaza/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include/"  -I"/software/R/lib64/R/library/RcppEigen/include/"  -I"/software/R/lib64/R/library/RcppEigen/include/unsupported"  -I"/software/R/lib64/R/library/BH/include" -I"/home/s/sdaza/R/x86_64-pc-linux-gnu-library/4.0/StanHeaders/include/src/"  -I"/home/s/sdaza/R/x86_64-pc-linux-gnu-library/4.0/StanHeaders/include/"  -I"/home/s/sdaza/R/x86_64-pc-linux-gnu-library/4.0/RcppParallel/include/"  -I"/home/s/sdaza/R/x86_64-pc-linux-gnu-library/4.0/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DBOOST_NO_AUTO_PTR  -include '/home/s/sdaza/R/x86_64-pc-linux-gnu-library/4.0/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp'  -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 
 >> Program source :

   1 : 
   2 : // includes from the plugin
   3 : // [[Rcpp::plugins(cpp14)]]
   4 : 
   5 : 
   6 : // user includes
   7 : #include <Rcpp.h>
   8 : #include <rstan/io/rlist_ref_var_context.hpp>
   9 : #include <rstan/io/r_ostream.hpp>
  10 : #include <rstan/stan_args.hpp>
  11 : #include <boost/integer/integer_log2.hpp>
  12 : // Code generated by Stan version 2.21.0
  13 : 
  14 : #include <stan/model/model_header.hpp>
  15 : 
  16 : namespace model1cb523508902dd_35830db9246beefe3363141b64f17491_namespace {
  17 : 
  18 : using std::istream;
  19 : using std::string;
  20 : using std::stringstream;
  21 : using std::vector;
  22 : using stan::io::dump;
  23 : using stan::math::lgamma;
  24 : using stan::model::prob_grad;
  25 : using namespace stan::math;
  26 : 
  27 : static int current_statement_begin__;
  28 : 
  29 : stan::io::program_reader prog_reader__() {
  30 :     stan::io::program_reader reader;
  31 :     reader.add_event(0, 0, "start", "model1cb523508902dd_35830db9246beefe3363141b64f17491");
  32 :     reader.add_event(10, 8, "end", "model1cb523508902dd_35830db9246beefe3363141b64f17491");
  33 :     return reader;
  34 : }
  35 : 
  36 : class model1cb523508902dd_35830db9246beefe3363141b64f17491
  37 :   : public stan::model::model_base_crtp<model1cb523508902dd_35830db9246beefe3363141b64f17491> {
  38 : private:
  39 : public:
  40 :     model1cb523508902dd_35830db9246beefe3363141b64f17491(rstan::io::rlist_ref_var_context& context__,
  41 :         std::ostream* pstream__ = 0)
  42 :         : model_base_crtp(0) {
  43 :         ctor_body(context__, 0, pstream__);
  44 :     }
  45 : 
  46 :     model1cb523508902dd_35830db9246beefe3363141b64f17491(stan::io::var_context& context__,
  47 :         unsigned int random_seed__,
  48 :         std::ostream* pstream__ = 0)
  49 :         : model_base_crtp(0) {
  50 :         ctor_body(context__, random_seed__, pstream__);
  51 :     }
  52 : 
  53 :     void ctor_body(stan::io::var_context& context__,
  54 :                    unsigned int random_seed__,
  55 :                    std::ostream* pstream__) {
  56 :         typedef double local_scalar_t__;
  57 : 
  58 :         boost::ecuyer1988 base_rng__ =
  59 :           stan::services::util::create_rng(random_seed__, 0);
  60 :         (void) base_rng__;  // suppress unused var warning
  61 : 
  62 :         current_statement_begin__ = -1;
  63 : 
  64 :         static const char* function__ = "model1cb523508902dd_35830db9246beefe3363141b64f17491_namespace::model1cb523508902dd_35830db9246beefe3363141b64f17491";
  65 :         (void) function__;  // dummy to suppress unused var warning
  66 :         size_t pos__;
  67 :         (void) pos__;  // dummy to suppress unused var warning
  68 :         std::vector<int> vals_i__;
  69 :         std::vector<double> vals_r__;
  70 :         local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
  71 :         (void) DUMMY_VAR__;  // suppress unused var warning
  72 : 
  73 :         try {
  74 :             // initialize data block variables from context__
  75 : 
  76 :             // initialize transformed data variables
  77 :             // execute transformed data statements
  78 : 
  79 :             // validate transformed data
  80 : 
  81 :             // validate, set parameter ranges
  82 :             num_params_r__ = 0U;
  83 :             param_ranges_i__.clear();
  84 :             current_statement_begin__ = 3;
  85 :             validate_non_negative_index("y", "2", 2);
  86 :             num_params_r__ += (1 * 2);
  87 :         } catch (const std::exception& e) {
  88 :             stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__());
  89 :             // Next line prevents compiler griping about no return
  90 :             throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
  91 :         }
  92 :     }
  93 : 
  94 :     ~model1cb523508902dd_35830db9246beefe3363141b64f17491() { }
  95 : 
  96 : 
  97 :     void transform_inits(const stan::io::var_context& context__,
  98 :                          std::vector<int>& params_i__,
  99 :                          std::vector<double>& params_r__,
 100 :                          std::ostream* pstream__) const {
 101 :         typedef double local_scalar_t__;
 102 :         stan::io::writer<double> writer__(params_r__, params_i__);
 103 :         size_t pos__;
 104 :         (void) pos__; // dummy call to supress warning
 105 :         std::vector<double> vals_r__;
 106 :         std::vector<int> vals_i__;
 107 : 
 108 :         current_statement_begin__ = 3;
 109 :         if (!(context__.contains_r("y")))
 110 :             stan::lang::rethrow_located(std::runtime_error(std::string("Variable y missing")), current_statement_begin__, prog_reader__());
 111 :         vals_r__ = context__.vals_r("y");
 112 :         pos__ = 0U;
 113 :         validate_non_negative_index("y", "2", 2);
 114 :         context__.validate_dims("parameter initialization", "y", "double", context__.to_vec(2));
 115 :         std::vector<double> y(2, double(0));
 116 :         size_t y_k_0_max__ = 2;
 117 :         for (size_t k_0__ = 0; k_0__ < y_k_0_max__; ++k_0__) {
 118 :             y[k_0__] = vals_r__[pos__++];
 119 :         }
 120 :         size_t y_i_0_max__ = 2;
 121 :         for (size_t i_0__ = 0; i_0__ < y_i_0_max__; ++i_0__) {
 122 :             try {
 123 :                 writer__.scalar_unconstrain(y[i_0__]);
 124 :             } catch (const std::exception& e) {
 125 :                 stan::lang::rethrow_located(std::runtime_error(std::string("Error transforming variable y: ") + e.what()), current_statement_begin__, prog_reader__());
 126 :             }
 127 :         }
 128 : 
 129 :         params_r__ = writer__.data_r();
 130 :         params_i__ = writer__.data_i();
 131 :     }
 132 : 
 133 :     void transform_inits(const stan::io::var_context& context,
 134 :                          Eigen::Matrix<double, Eigen::Dynamic, 1>& params_r,
 135 :                          std::ostream* pstream__) const {
 136 :       std::vector<double> params_r_vec;
 137 :       std::vector<int> params_i_vec;
 138 :       transform_inits(context, params_i_vec, params_r_vec, pstream__);
 139 :       params_r.resize(params_r_vec.size());
 140 :       for (int i = 0; i < params_r.size(); ++i)
 141 :         params_r(i) = params_r_vec[i];
 142 :     }
 143 : 
 144 : 
 145 :     template <bool propto__, bool jacobian__, typename T__>
 146 :     T__ log_prob(std::vector<T__>& params_r__,
 147 :                  std::vector<int>& params_i__,
 148 :                  std::ostream* pstream__ = 0) const {
 149 : 
 150 :         typedef T__ local_scalar_t__;
 151 : 
 152 :         local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
 153 :         (void) DUMMY_VAR__;  // dummy to suppress unused var warning
 154 : 
 155 :         T__ lp__(0.0);
 156 :         stan::math::accumulator<T__> lp_accum__;
 157 :         try {
 158 :             stan::io::reader<local_scalar_t__> in__(params_r__, params_i__);
 159 : 
 160 :             // model parameters
 161 :             current_statement_begin__ = 3;
 162 :             std::vector<local_scalar_t__> y;
 163 :             size_t y_d_0_max__ = 2;
 164 :             y.reserve(y_d_0_max__);
 165 :             for (size_t d_0__ = 0; d_0__ < y_d_0_max__; ++d_0__) {
 166 :                 if (jacobian__)
 167 :                     y.push_back(in__.scalar_constrain(lp__));
 168 :                 else
 169 :                     y.push_back(in__.scalar_constrain());
 170 :             }
 171 : 
 172 :             // model body
 173 : 
 174 :             current_statement_begin__ = 6;
 175 :             lp_accum__.add(normal_log<propto__>(get_base1(y, 1, "y", 1), 0, 1));
 176 :             current_statement_begin__ = 7;
 177 :             lp_accum__.add(double_exponential_log<propto__>(get_base1(y, 2, "y", 1), 0, 2));
 178 : 
 179 :         } catch (const std::exception& e) {
 180 :             stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__());
 181 :             // Next line prevents compiler griping about no return
 182 :             throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
 183 :         }
 184 : 
 185 :         lp_accum__.add(lp__);
 186 :         return lp_accum__.sum();
 187 : 
 188 :     } // log_prob()
 189 : 
 190 :     template <bool propto, bool jacobian, typename T_>
 191 :     T_ log_prob(Eigen::Matrix<T_,Eigen::Dynamic,1>& params_r,
 192 :                std::ostream* pstream = 0) const {
 193 :       std::vector<T_> vec_params_r;
 194 :       vec_params_r.reserve(params_r.size());
 195 :       for (int i = 0; i < params_r.size(); ++i)
 196 :         vec_params_r.push_back(params_r(i));
 197 :       std::vector<int> vec_params_i;
 198 :       return log_prob<propto,jacobian,T_>(vec_params_r, vec_params_i, pstream);
 199 :     }
 200 : 
 201 : 
 202 :     void get_param_names(std::vector<std::string>& names__) const {
 203 :         names__.resize(0);
 204 :         names__.push_back("y");
 205 :     }
 206 : 
 207 : 
 208 :     void get_dims(std::vector<std::vector<size_t> >& dimss__) const {
 209 :         dimss__.resize(0);
 210 :         std::vector<size_t> dims__;
 211 :         dims__.resize(0);
 212 :         dims__.push_back(2);
 213 :         dimss__.push_back(dims__);
 214 :     }
 215 : 
 216 :     template <typename RNG>
 217 :     void write_array(RNG& base_rng__,
 218 :                      std::vector<double>& params_r__,
 219 :                      std::vector<int>& params_i__,
 220 :                      std::vector<double>& vars__,
 221 :                      bool include_tparams__ = true,
 222 :                      bool include_gqs__ = true,
 223 :                      std::ostream* pstream__ = 0) const {
 224 :         typedef double local_scalar_t__;
 225 : 
 226 :         vars__.resize(0);
 227 :         stan::io::reader<local_scalar_t__> in__(params_r__, params_i__);
 228 :         static const char* function__ = "model1cb523508902dd_35830db9246beefe3363141b64f17491_namespace::write_array";
 229 :         (void) function__;  // dummy to suppress unused var warning
 230 : 
 231 :         // read-transform, write parameters
 232 :         std::vector<double> y;
 233 :         size_t y_d_0_max__ = 2;
 234 :         y.reserve(y_d_0_max__);
 235 :         for (size_t d_0__ = 0; d_0__ < y_d_0_max__; ++d_0__) {
 236 :             y.push_back(in__.scalar_constrain());
 237 :         }
 238 :         size_t y_k_0_max__ = 2;
 239 :         for (size_t k_0__ = 0; k_0__ < y_k_0_max__; ++k_0__) {
 240 :             vars__.push_back(y[k_0__]);
 241 :         }
 242 : 
 243 :         double lp__ = 0.0;
 244 :         (void) lp__;  // dummy to suppress unused var warning
 245 :         stan::math::accumulator<double> lp_accum__;
 246 : 
 247 :         local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
 248 :         (void) DUMMY_VAR__;  // suppress unused var warning
 249 : 
 250 :         if (!include_tparams__ && !include_gqs__) return;
 251 : 
 252 :         try {
 253 :             if (!include_gqs__ && !include_tparams__) return;
 254 :             if (!include_gqs__) return;
 255 :         } catch (const std::exception& e) {
 256 :             stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__());
 257 :             // Next line prevents compiler griping about no return
 258 :             throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
 259 :         }
 260 :     }
 261 : 
 262 :     template <typename RNG>
 263 :     void write_array(RNG& base_rng,
 264 :                      Eigen::Matrix<double,Eigen::Dynamic,1>& params_r,
 265 :                      Eigen::Matrix<double,Eigen::Dynamic,1>& vars,
 266 :                      bool include_tparams = true,
 267 :                      bool include_gqs = true,
 268 :                      std::ostream* pstream = 0) const {
 269 :       std::vector<double> params_r_vec(params_r.size());
 270 :       for (int i = 0; i < params_r.size(); ++i)
 271 :         params_r_vec[i] = params_r(i);
 272 :       std::vector<double> vars_vec;
 273 :       std::vector<int> params_i_vec;
 274 :       write_array(base_rng, params_r_vec, params_i_vec, vars_vec, include_tparams, include_gqs, pstream);
 275 :       vars.resize(vars_vec.size());
 276 :       for (int i = 0; i < vars.size(); ++i)
 277 :         vars(i) = vars_vec[i];
 278 :     }
 279 : 
 280 :     std::string model_name() const {
 281 :         return "model1cb523508902dd_35830db9246beefe3363141b64f17491";
 282 :     }
 283 : 
 284 : 
 285 :     void constrained_param_names(std::vector<std::string>& param_names__,
 286 :                                  bool include_tparams__ = true,
 287 :                                  bool include_gqs__ = true) const {
 288 :         std::stringstream param_name_stream__;
 289 :         size_t y_k_0_max__ = 2;
 290 :         for (size_t k_0__ = 0; k_0__ < y_k_0_max__; ++k_0__) {
 291 :             param_name_stream__.str(std::string());
 292 :             param_name_stream__ << "y" << '.' << k_0__ + 1;
 293 :             param_names__.push_back(param_name_stream__.str());
 294 :         }
 295 : 
 296 :         if (!include_gqs__ && !include_tparams__) return;
 297 : 
 298 :         if (include_tparams__) {
 299 :         }
 300 : 
 301 :         if (!include_gqs__) return;
 302 :     }
 303 : 
 304 : 
 305 :     void unconstrained_param_names(std::vector<std::string>& param_names__,
 306 :                                    bool include_tparams__ = true,
 307 :                                    bool include_gqs__ = true) const {
 308 :         std::stringstream param_name_stream__;
 309 :         size_t y_k_0_max__ = 2;
 310 :         for (size_t k_0__ = 0; k_0__ < y_k_0_max__; ++k_0__) {
 311 :             param_name_stream__.str(std::string());
 312 :             param_name_stream__ << "y" << '.' << k_0__ + 1;
 313 :             param_names__.push_back(param_name_stream__.str());
 314 :         }
 315 : 
 316 :         if (!include_gqs__ && !include_tparams__) return;
 317 : 
 318 :         if (include_tparams__) {
 319 :         }
 320 : 
 321 :         if (!include_gqs__) return;
 322 :     }
 323 : 
 324 : }; // model
 325 : 
 326 : }  // namespace
 327 : 
 328 : typedef model1cb523508902dd_35830db9246beefe3363141b64f17491_namespace::model1cb523508902dd_35830db9246beefe3363141b64f17491 stan_model;
 329 : 
 330 : #ifndef USING_R
 331 : 
 332 : stan::model::model_base& new_model(
 333 :         stan::io::var_context& data_context,
 334 :         unsigned int seed,
 335 :         std::ostream* msg_stream) {
 336 :   stan_model* m = new stan_model(data_context, seed, msg_stream);
 337 :   return *m;
 338 : }
 339 : 
 340 : #endif
 341 : 
 342 : 
 343 : 
 344 : #include <rstan_next/stan_fit.hpp>
 345 : 
 346 : struct stan_model_holder {
 347 :     stan_model_holder(rstan::io::rlist_ref_var_context rcontext,
 348 :                       unsigned int random_seed)
 349 :     : rcontext_(rcontext), random_seed_(random_seed)
 350 :      {
 351 :      }
 352 : 
 353 :    //stan::math::ChainableStack ad_stack;
 354 :    rstan::io::rlist_ref_var_context rcontext_;
 355 :    unsigned int random_seed_;
 356 : };
 357 : 
 358 : Rcpp::XPtr<stan::model::model_base> model_ptr(stan_model_holder* smh) {
 359 :   Rcpp::XPtr<stan::model::model_base> model_instance(new stan_model(smh->rcontext_, smh->random_seed_), true);
 360 :   return model_instance;
 361 : }
 362 : 
 363 : Rcpp::XPtr<rstan::stan_fit_base> fit_ptr(stan_model_holder* smh) {
 364 :   return Rcpp::XPtr<rstan::stan_fit_base>(new rstan::stan_fit(model_ptr(smh), smh->random_seed_), true);
 365 : }
 366 : 
 367 : std::string model_name(stan_model_holder* smh) {
 368 :   return model_ptr(smh).get()->model_name();
 369 : }
 370 : 
 371 : RCPP_MODULE(stan_fit4model1cb523508902dd_35830db9246beefe3363141b64f17491_mod){
 372 :   Rcpp::class_<stan_model_holder>("stan_fit4model1cb523508902dd_35830db9246beefe3363141b64f17491")
 373 :   .constructor<rstan::io::rlist_ref_var_context, unsigned int>()
 374 :   .method("model_ptr", &model_ptr)
 375 :   .method("fit_ptr", &fit_ptr)
 376 :   .method("model_name", &model_name)
 377 :   ;
 378 : }
 379 : 
 380 : 
 381 : // declarations
 382 : extern "C" {
 383 : SEXP file1cb523680955c9( ) ;
 384 : }
 385 : 
 386 : // definition
 387 : 
 388 : SEXP file1cb523680955c9(  ){
 389 :  return Rcpp::wrap("35830db9246beefe3363141b64f17491");
 390 : }
 391 : 
 392 : 
make cmd is
  make -f '/software/R/lib64/R/etc/Makeconf' -f '/software/R/lib64/R/share/make/shlib.mk' -f '/home/s/sdaza/.R/Makevars' CXX='$(CXX14) $(CXX14STD)' CXXFLAGS='$(CXX14FLAGS)' CXXPICFLAGS='$(CXX14PICFLAGS)' SHLIB_LDFLAGS='$(SHLIB_CXX14LDFLAGS)' SHLIB_LD='$(SHLIB_CXX14LD)' SHLIB='file1cb523680955c9.so' OBJECTS='file1cb523680955c9.o'

make would use
g++  -I"/software/R/lib64/R/include" -DNDEBUG   -I"/home/s/sdaza/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include/"  -I"/software/R/lib64/R/library/RcppEigen/include/"  -I"/software/R/lib64/R/library/RcppEigen/include/unsupported"  -I"/software/R/lib64/R/library/BH/include" -I"/home/s/sdaza/R/x86_64-pc-linux-gnu-library/4.0/StanHeaders/include/src/"  -I"/home/s/sdaza/R/x86_64-pc-linux-gnu-library/4.0/StanHeaders/include/"  -I"/home/s/sdaza/R/x86_64-pc-linux-gnu-library/4.0/RcppParallel/include/"  -I"/home/s/sdaza/R/x86_64-pc-linux-gnu-library/4.0/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DBOOST_NO_AUTO_PTR  -include '/home/s/sdaza/R/x86_64-pc-linux-gnu-library/4.0/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp'  -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1   -I/usr/local/include     -O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function -fPIC -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -flto -Wno-unused-local-typedefs -Wno-ignored-attributes -Wno-deprecated-declarations -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -c file1cb523680955c9.cpp -o file1cb523680955c9.o
if test  "zfile1cb523680955c9.o" != "z"; then \
  echo g++  -shared -L"/software/R/lib64/R/lib" -L/usr/local/lib64 -o file1cb523680955c9.so file1cb523680955c9.o  '/home/s/sdaza/R/x86_64-pc-linux-gnu-library/4.0/rstan/lib//libStanServices.a' -L'/home/s/sdaza/R/x86_64-pc-linux-gnu-library/4.0/StanHeaders/lib/' -lStanHeaders -L'/home/s/sdaza/R/x86_64-pc-linux-gnu-library/4.0/RcppParallel/lib/' -ltbb  -L"/software/R/lib64/R/lib" -lR; \
  g++  -shared -L"/software/R/lib64/R/lib" -L/usr/local/lib64 -o file1cb523680955c9.so file1cb523680955c9.o  '/home/s/sdaza/R/x86_64-pc-linux-gnu-library/4.0/rstan/lib//libStanServices.a' -L'/home/s/sdaza/R/x86_64-pc-linux-gnu-library/4.0/StanHeaders/lib/' -lStanHeaders -L'/home/s/sdaza/R/x86_64-pc-linux-gnu-library/4.0/RcppParallel/lib/' -ltbb  -L"/software/R/lib64/R/lib" -lR; \
fi
Error in dyn.load(libLFile) : 
  unable to load shared object '/tmp/RtmpXLE2Io/file1cb523680955c9.so':
  /tmp/RtmpXLE2Io/file1cb523680955c9.so: undefined symbol: _ZN5rstan8stan_fitC1EP7SEXPRECi
In addition: Warning message:
In system(paste(CPP, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
  error in running command

traceback() is:

6: dyn.load(libLFile)
5: cxxfunction(sig = sig, body = body, plugin = plugin, includes = includes, 
       settings = settings, ..., verbose = verbose)
4: pkgbuild::with_build_tools(cxxfunction(sig = sig, body = body, 
       plugin = plugin, includes = includes, settings = settings, 
       ..., verbose = verbose), required = rstan_options("required") && 
       !identical(Sys.getenv("WINDOWS"), "TRUE") && !identical(Sys.getenv("R_PACKAGE_SOURCE"), 
       ""))
3: cxxfunctionplus(signature(), body = paste(" return Rcpp::wrap(\"", 
       model_name, "\");", sep = ""), includes = inc, plugin = "rstan", 
       save_dso = save_dso | auto_write, module_name = paste("stan_fit4", 
           model_cppname, "_mod", sep = ""), verbose = verbose)
2: stan_model(file, model_name = model_name, model_code = model_code, 
       stanc_ret = NULL, boost_lib = boost_lib, eigen_lib = eigen_lib, 
       save_dso = save_dso, verbose = verbose)
1: stan(model_code = scode, iter = 10, verbose = TRUE)

My system:

> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS:   /software/R/lib64/R/lib/libRblas.so
LAPACK: /software/R/lib64/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8    
 [5] LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8   
 [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] rstan_2.21.3         ggplot2_3.3.2        StanHeaders_2.21.0-6

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5         pillar_1.4.6       compiler_4.0.2     prettyunits_1.1.1 
 [5] tools_4.0.2        pkgbuild_1.1.0     jsonlite_1.7.1     lifecycle_0.2.0   
 [9] tibble_3.0.4       gtable_0.3.0       pkgconfig_2.0.3    rlang_0.4.8       
[13] cli_2.1.0          parallel_4.0.2     curl_4.3           loo_2.3.1         
[17] gridExtra_2.3      withr_2.3.0        dplyr_1.0.0        generics_0.0.2    
[21] vctrs_0.3.4        stats4_4.0.2       grid_4.0.2         tidyselect_1.1.0  
[25] glue_1.4.2         inline_0.3.16      R6_2.4.1           processx_3.4.4    
[29] fansi_0.4.1        callr_3.5.1        purrr_0.3.4        magrittr_1.5      
[33] codetools_0.2-16   scales_1.1.1       ps_1.4.0           ellipsis_0.3.1    
[37] matrixStats_0.57.0 assertthat_0.2.1   colorspace_1.4-1   V8_3.2.0          
[41] RcppParallel_5.0.2 munsell_0.5.0      crayon_1.3.4  

Any ideas or suggestions?
Thanks!

What version of g++?

This:

g++ (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> Sys.which("g++")
                                    g++ 
"/opt/rh/devtoolset-7/root/usr/bin/g++"

makevars

# created by rstan
CXX14FLAGS=-O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function -fPIC -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION
CXX14 = g++
CXX14FLAGS+=-flto -Wno-unused-local-typedefs -Wno-ignored-attributes -Wno-deprecated-declarations -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION

thanks!

Were Rcpp and RcppParallel compiled with the same compiler (settings)?

No idea…

I would try installing both of those from source and then possibly reinstalling rstan.

Thanks, I did, no changes:

> fit1 <- brm(count ~ zAge + zBase * Trt + (1|patient), 
+             data = epilepsy, family = poisson())
Compiling Stan program...
'config' variable 'CPP' is deprecated
gcc -std=gnu99 -E
Error in dyn.load(libLFile) : 
  unable to load shared object '/tmp/RtmpaLqxIT/file17c1ee7137890.so':
  /tmp/RtmpaLqxIT/file17c1ee7137890.so: undefined symbol: _ZN5rstan8stan_fitC1EP7SEXPRECi
In addition: Warning message:
In system(paste(CPP, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
  error in running command
Error in sink(type = "output") : invalid connection

Does

example(cxxfunction, package = "inline", run.dontrun = TRUE)

work ?

I got this:

> example(cxxfunction, package = "inline", run.dontrun = TRUE)

cxxfnc> # default plugin
cxxfnc> fx <- cxxfunction( signature(x = "integer", y = "numeric" ) , '
cxxfnc+         return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ;
cxxfnc+ ' )

cxxfnc> fx( 2L, 5 )
[1] 10

cxxfnc> # Rcpp plugin
cxxfnc> if( require( Rcpp ) ){
cxxfnc+ 
cxxfnc+         fx <- cxxfunction( signature(x = "integer", y = "numeric" ) , '
cxxfnc+                 return wrap( as<int>(x) * as<double>(y) ) ;
cxxfnc+         ', plugin = "Rcpp" )
cxxfnc+         fx( 2L, 5 )
cxxfnc+ 
cxxfnc+         ## equivalent shorter form using rcpp()
cxxfnc+         fx <- rcpp(signature(x = "integer", y = "numeric"),
cxxfnc+                    ' return wrap( as<int>(x) * as<double>(y) ) ; ')
cxxfnc+ 
cxxfnc+ }
Loading required package: Rcpp

Attaching package: ‘Rcpp’

The following object is masked from ‘package:inline’:

    registerPlugin


cxxfnc> # RcppArmadillo plugin
cxxfnc> if( require( RcppArmadillo ) ){
cxxfnc+ 
cxxfnc+         fx <- cxxfunction( signature(x = "integer", y = "numeric" ) , '
cxxfnc+                 int dim = as<int>( x ) ;
cxxfnc+                 arma::mat z = as<double>(y) * arma::eye<arma::mat>( dim, dim ) ;
cxxfnc+                 return wrap( arma::accu(z) ) ;
cxxfnc+         ', plugin = "RcppArmadillo" )
cxxfnc+         fx( 2L, 5 )
cxxfnc+ 
cxxfnc+ 
cxxfnc+ }
Loading required package: RcppArmadillo
[1] 10

Thanks!

OK. Can you try a Stan thing again after chainging your ~/.R/Makevars to

CXX14 = g++ -std=c++14

?

Nothing :(

fit <- stan(model_code = modelscript, data = schools_dat)
Error in dyn.load(libLFile) :
unable to load shared object ‘/tmp/RtmpzbBZgr/file2cd67a7586540.so’:
/tmp/RtmpzbBZgr/file2cd67a7586540.so: undefined symbol: _ZN5rstan8stan_fitC1EP7SEXPRECi
Calls: stan … cxxfunctionplus -> -> cxxfunction -> dyn.load
Error in sink(type = “output”) : invalid connection
Calls: stan -> stan_model -> cxxfunctionplus -> sink
Execution halted

Do you have any other compiler versions available on that machine?

Thanks, Ben. Finally, it worked by setting my Makevars as:

CXX14FLAGS=-O3 -march=native -mtune=native -fPIC
CXX14=/opt/rh/devtoolset-8/root/usr/bin/g++

OK, that seems to indicate that g++ (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5) may have a bug.