Problem installing cmdstan with R4.2 and RTools42

Hi everyone,

I recently updated to R4.2.1 (and RTools42) , and I’m now encountering problems when trying to reinstall cmdstanr.

When I tried to install cmdstan using the install_cmdstan function in cmdstanr, I encountered the following error:

The C++ toolchain required for CmdStan is setup properly!
* Latest CmdStan release is v2.30.1
* Installing CmdStan v2.30.1 in C:/Users/PeteS/OneDrive/St%20Andrews/Documents/.cmdstan/cmdstan-2.30.1
* Downloading cmdstan-2.30.1.tar.gz from GitHub...
Error: Download of CmdStan failed. Please try again.

I checked in the .cmdstan folder and the .tar.gz file looks far too small (5664 KB) and when I try to extract it with 7-zip it shows the error: “Unexpected end of data : cmdstan-2.30.1.tar”

I then tried downloading the latest cmdstan release manually from GitHub (from here) - this appears to download successfully, and the file is much larger (48400 KB). I copied the .tar.gz file into the .cmdstan folder, extracted it, and then extracted the .tar file (both using 7-zip).

I then set the cmdstan path to the folder using the set_cmdstan_path function, and restarted R. Running cmdstan_path() showed that the path was still pointing to the folder to which I’d set it. Running check_cmdstan_toolchain returned The C++ toolchain required for CmdStan is setup properly!

However, when I try to run the cmdstan example model from here, the model fails to compile and returns the following error:

Compiling Stan program...
INFO: Could not find files for the given pattern(s).

INFO: Could not find files for the given pattern(s).

ar: 
creating stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_nvecserial.a

ar: 
creating stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_cvodes.a

ar: 
creating stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_idas.a

ar: 
creating stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_kinsol.a

In file included from stan/lib/stan_math/lib/boost_1.78.0/boost/multi_array/multi_array_ref.hpp:32,
                 from stan/lib/stan_math/lib/boost_1.78.0/boost/multi_array.hpp:34,
                 from stan/lib/stan_math/lib/boost_1.78.0/boost/numeric/odeint/algebra/multi_array_algebra.hpp:22,
                 from stan/lib/stan_math/lib/boost_1.78.0/boost/numeric/odeint.hpp:63,
                 from stan/lib/stan_math/stan/math/prim/functor/ode_rk45.hpp:9,
                 from stan/lib/stan_math/stan/math/prim/functor/integrate_ode_rk45.hpp:6,
                 from stan/lib/stan_math/stan/math/prim/functor.hpp:14,
                 from stan/lib/stan_math/stan/math/prim.hpp:15,
                 from stan/src/stan/io/dump.hpp:7,
                 from src/cmdstan/command.hpp:30,
                 from src/cmdstan/main.cpp:1:
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:180:45: warning: 'template<class _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
  180 |         : public boost::functional::detail::unary_function<typename unary_traits<Predicate>::argument_type,bool>
      |                                             ^~~~~~~~~~~~~~

In file included from C:/rtools42/ucrt64/include/c++/12.2.0/string:48,
                 from C:/rtools42/ucrt64/include/c++/12.2.0/bits/locale_classes.h:40,
                 from C:/rtools42/ucrt64/include/c++/12.2.0/bits/ios_base.h:41,
                 from C:/rtools42/ucrt64/include/c++/12.2.0/streambuf:41,
                 from C:/rtools42/ucrt64/include/c++/12.2.0/bits/streambuf_iterator.h:35,
                 from C:/rtools42/ucrt64/include/c++/12.2.0/iterator:66,
                 from stan/lib/stan_math/lib/boost_1.78.0/boost/iterator/iterator_traits.hpp:10,
                 from stan/lib/stan_math/lib/boost_1.78.0/boost/range/iterator_range_core.hpp:26,
                 from stan/lib/stan_math/lib/boost_1.78.0/boost/lexical_cast.hpp:30,
                 from stan/src/stan/callbacks/writer.hpp:4,
                 from src/cmdstan/arguments/argument.hpp:4,
                 from src/cmdstan/arguments/categorical_argument.hpp:4,
                 from src/cmdstan/arguments/arg_data.hpp:4,
                 from src/cmdstan/command.hpp:4:
C:/rtools42/ucrt64/include/c++/12.2.0/bits/stl_function.h:117:12: note: declared here
  117 |     struct unary_function
      |            ^~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:214:45: warning: 'template<class _Arg1, class _Arg2, class _Result> struct std::binary_function' is deprecated [-Wdeprecated-declarations]
  214 |         : public boost::functional::detail::binary_function<
      |                                             ^~~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/12.2.0/bits/stl_function.h:131:12: note: declared here
  131 |     struct binary_function
      |            ^~~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:252:45: warning: 'template<class _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
  252 |         : public boost::functional::detail::unary_function<
      |                                             ^
~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/12.2.0/bits/stl_function.h:117:12: note: declared here
  117 |     struct unary_function
      |            ^~~~~~~~~~~~~~

stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:299:45: warning: 'template<class _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
  299 |         : public boost::functional::detail::unary_function<
      |                                             ^~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/12.2.0/bits/stl_function.h:117:12: note: declared here
  117 |     struct unary_function
      |            ^~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:345:57: warning: 'template<class _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
  345 |     class mem_fun_t : public boost::functional::detail::unary_function<T*, S>
      |                                                         ^~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/12.2.0/bits/stl_function.h:117:12: note: declared here
  117 |     struct unary_function
      |            ^~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:361:58: warning: 'template<class _Arg1, class _Arg2, class _Result> struct std::binary_function' is deprecated [-Wdeprecated-declarations]
  361 |     class mem_fun1_t : public boost::functional::detail::binary_function<T*, A, S>
      |                                                          ^~~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/12.2.0/bits/stl_function.h:131:12: note: declared here
  131 |     struct binary_function
      |            ^~~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:377:63: warning: 'template<class _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
  377 |     class const_mem_fun_t : public boost::functional::detail::unary_function<const T*, S>
      |                                                               ^~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/12.2.0/bits/stl_function.h:117:12: note: declared here
  117 |     struct unary_function
      |            ^~~
~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:393:64: warning: 'template<class _Arg1, class _Arg2, class _Result> struct std::binary_function' is deprecated [-Wdeprecated-declarations]
  393 |     class const_mem_fun1_t : public boost::functional::detail::binary_function<const T*, A, S>
      |                                                                ^~~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/12.2.0/bits/stl_function.h:131:12: note: declared here
  131 |     struct binary_function
      |            ^~~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:438:61: warning: 'template<class _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
  438 |     class mem_fun_ref_t : public boost::functional::detail::unary_function<T&, S>
      |                                                             ^~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/12.2.0/bits/stl_function.h:117:12: note: declared here
  117 |     struct unary_function
      |            ^~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:454:62: warning: 'template<class _Arg1, class _Arg2, class _Result> struct std::binary_function' is deprecated [-Wdeprecated-declarations]
  454 |     class mem_fun1_ref_t : public boost::functional::detail::binary_function<T&, A, S>
      |                                                              ^~~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/12.2.0/bits/stl_function.h:131:12: note: declared here
  131 |     struct binary_function
      |            ^~~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:470:67: warning: 'template<class _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
  470 |     class const_mem_fun_ref_t : public boost::functional::detail::unary_function<const T&, S>
      |                                                                   ^~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/12.
2.0/bits/stl_function.h:117:12: note: declared here
  117 |     struct unary_function
      |            ^~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:487:68: warning: 'template<class _Arg1, class _Arg2, class _Result> struct std::binary_function' is deprecated [-Wdeprecated-declarations]
  487 |     class const_mem_fun1_ref_t : public boost::functional::detail::binary_function<const T&, A, S>
      |                                                                    ^~~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/12.2.0/bits/stl_function.h:131:12: note: declared here
  131 |     struct binary_function
      |            ^~~~~~~~~~~~~~~

stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:533:73: warning: 'template<class _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
  533 |     class pointer_to_unary_function : public boost::functional::detail::unary_function<Arg,Result>
      |                                                                         ^~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/12.2.0/bits/stl_function.h:117:12: note: declared here
  117 |     struct unary_function
      |            ^~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:557:74: warning: 'template<class _Arg1, class _Arg2, class _Result> struct std::binary_function' is deprecated [-Wdeprecated-declarations]
  557 |     class pointer_to_binary_function : public boost::functional::detail::binary_function<Arg1,Arg2,Result>
      |                                                                          ^~~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/12.2.0/bits/stl_function.h:131:12: note: declared here
  131 |     struct binary_function
      |            ^~~~~~~~~~~~~~~

In file included from C:/rtools42/ucrt64/include/c++/12.2.0/stdlib.h:36,
                 from C:/rtools42/ucrt64/lib/gcc/x86_64-w64-mingw32/12.2.0/include/mm_malloc.h:27,
                 from C:/rtools42/ucrt64/lib/gcc/x86_64-w64-mingw32/12.2.0/include/xmmintrin.h:34,
                 from C:/rtools42/ucrt64/lib/gcc/x86_64-w64-mingw32/12.2.0/include/immintrin.h:31,
                 from ../tbb_2020.3/include/tbb/machine/gcc_itsx.h:57,
                 from ../tbb_2020.3/include/tbb/machine/gcc_ia32_common.h:107,
                 from ../tbb_2020.3/include/tbb/machine/gcc_generic.h:232,
                 from ../tbb_2020.3/include/tbb/tbb_machine.h:197,
                 from ../tbb_2020.3/src/tbbmalloc/Synchronize.h:20,
                 from ../tbb_2020.3/src/tbbmalloc/Customize.h:29,
                 from ../tbb_2020.3/src/tbbmalloc/TypeDefinitions.h:54,
                 from ../tbb_2020.3/src/tbbmalloc/tbbmalloc_internal.h:21,
                 from ../tbb_2020.3/src/tbbmalloc/backend.cpp:19:
C:/rtools42/ucrt64/include/c++/12.2.0/cstdlib:137:11: error: 'at_quick_exit' has not been declared in '::'
  137 |   using ::at_quick_exit;
      |           ^~~~~~~~~~~~~

C:/rtools42/ucrt64/include/c++/12.2.0/cstdlib:160:11: error: 'quick_exit' has not been declared in '::'
  160 |   using ::quick_exit;
      |           ^~~~~~~~~~
C:/rtools42/ucrt64/include/c++/12.2.0/stdlib.h:43:14: error: 'at_quick_exit' has not been declared in 'std'
   43 |   using std::at_quick_exit;
      |              ^~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/12.2.0/stdlib.h:46:14: error: 'quick_exit' has not been declared in 'std'
   46 |   using std::quick_exit;
      |              ^~~~~~~~~~

cc1plus.exe: note: unrecognized command-line option '-Wno-unknown-warning-option' may have been intended to silence earlier diagnostics

mingw32-make[1]: *** [C:/Users/PeteS/OneDrive/St%20Andrews/Documents/.cmdstan/cmdstan-2.30.1/stan/lib/stan_math/lib/tbb_2020.3/build/Makefile.tbbmalloc:65: backend.o] Error 1

mingw32-make: *** [stan/lib/stan_math/make/libraries:173: stan/lib/stan_math/lib/tbb/tbbmalloc.def] Error 2

Error: An error occured during compilation! See the message above for more information.
> cmdstan_version()
[1] "2.30.1"
> file <- file.path(cmdstan_path(), "examples", "bernoulli", "bernoulli.stan")
> mod <- cmdstan_model(file)
Compiling Stan program...
INFO: Could not find files for the given pattern(s).

INFO: Could not find files for the given pattern(s).

In file included from stan/lib/stan_math/lib/boost_1.78.0/boost/multi_array/multi_array_ref.hpp:32,
                 from stan/lib/stan_math/lib/boost_1.78.0/boost/multi_array.hpp:34,
                 from stan/lib/stan_math/lib/boost_1.78.0/boost/numeric/odeint/algebra/multi_array_algebra.hpp:22,
                 from stan/lib/stan_math/lib/boost_1.78.0/boost/numeric/odeint.hpp:63,
                 from stan/lib/stan_math/stan/math/prim/functor/ode_rk45.hpp:9,
                 from stan/lib/stan_math/stan/math/prim/functor/integrate_ode_rk45.hpp:6,
                 from stan/lib/stan_math/stan/math/prim/functor.hpp:14,
                 from stan/lib/stan_math/stan/math/prim.hpp:15,
                 from stan/src/stan/io/dump.hpp:7,
                 from src/cmdstan/command.hpp:30,
                 from src/cmdstan/main.cpp:1:
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:180:45: warning: 'template<class _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
  180 |         : public boost::functional::detail::unary_function<typename unary_traits<Predicate>::argument_type,bool>
      |                                             ^~~~~~~~~~~~~~

In file included from C:/rtools42/ucrt64/include/c++/12.2.0/string:48,
                 from C:/rtools42/ucrt64/include/c++/12.2.0/bits/locale_classes.h:40,
                 from C:/rtools42/ucrt64/include/c++/12.2.0/bits/ios_base.h:41,
                 from C:/rtools42/ucrt64/include/c++/12.2.0/streambuf:41,
                 from C:/rtools42/ucrt64/include/c++/12.2.0/bits/streambuf_iterator.h:35,
                 from C:/rtools42/ucrt64/include/c++/12.2.0/iterator:66,
                 from stan/lib/stan_math/lib/boost_1.78.0/boost/iterator/iterator_traits.hpp:10,
                 from stan/lib/stan_math/lib/boost_1.78.0/boost/range/iterator_range_core.hpp:26,
                 from stan/lib/stan_math/lib/boost_1.78.0/boost/lexical_cast.hpp:30,
                 from stan/src/stan/callbacks/writer.hpp:4,
                 from src/cmdstan/arguments/argument.hpp:4,
                 from src/cmdstan/arguments/categorical_argument.hpp:4,
                 from src/cmdstan/arguments/arg_data.hpp:4,
                 from src/cmdstan/command.hpp:4:
C:/rtools42/ucrt64/include/c++/12.2.0/bits/stl_function.h:117:12: note: declared here
  117 |     struct unary_function
      |            ^~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:214:45: warning: 'template<class _Arg1, class _Arg2, class _Result> struct std::binary_function' is deprecated [-Wdeprecated-declarations]
  214 |         : public boost::functional::detail::binary_function<
      |                                             ^~~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/12.2.0/bits/stl_function.h:131:12: note: declared here
  131 |     struct binary_function
      |            ^~~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:252:45: warning: 'template<class _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
  252 |         : public boost::functional::detail::unary_function<
      |                                             ^
~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/12.2.0/bits/stl_function.h:117:12: note: declared here
  117 |     struct unary_function
      |            ^~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:299:45: warning: 'template<class _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
  299 |         : public boost::functional::detail::unary_function<
      |                                             ^~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/12.2.0/bits/stl_function.h:117:12: note: declared here
  117 |     struct unary_function
      |            ^~~~~~~~~~~~~~

stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:345:57: warning: 'template<class _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
  345 |     class mem_fun_t : public boost::functional::detail::unary_function<T*, S>
      |                                                         ^~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/12.2.0/bits/stl_function.h:117:12: note: declared here
  117 |     struct unary_function
      |            ^~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:361:58: warning: 'template<class _Arg1, class _Arg2, class _Result> struct std::binary_function' is deprecated [-Wdeprecated-declarations]
  361 |     class mem_fun1_t : public boost::functional::detail::binary_function<T*, A, S>
      |                                                          ^~~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/12.2.0/bits/stl_function.h:131:12: note: declared here
  131 |     struct binary_function
      |            ^~~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:377:63: warning: 'template<class _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
  377 |     class const_mem_fun_t : public boost::functional::detail::unary_function<const T*, S>
      |                                                               ^~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/12.2.0/bits/stl_function.h:117:12: note: declared here
  117 |     struct unary_function
      |            ^~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:393:64: warning: 'template<class _Arg1, class _Arg2, class _Result> struct std::binary_function' is deprecated [-Wdeprecated-declarations]
  393 |     class const_mem_fun1_t : public boost::functional::detail::binary_function<const T*, A, S>
      |                                                                ^~~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/12.2.0/bits/stl_function.h:131:12: note: 
declared here
  131 |     struct binary_function
      |            ^~~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:438:61: warning: 'template<class _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
  438 |     class mem_fun_ref_t : public boost::functional::detail::unary_function<T&, S>
      |                                                             ^~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/12.2.0/bits/stl_function.h:117:12: note: declared here
  117 |     struct unary_function
      |            ^~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:454:62: warning: 'template<class _Arg1, class _Arg2, class _Result> struct std::binary_function' is deprecated [-Wdeprecated-declarations]
  454 |     class mem_fun1_ref_t : public boost::functional::detail::binary_function<T&, A, S>
      |                                                              ^~~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/12.2.0/bits/stl_function.h:131:12: note: declared here
  131 |     struct binary_function
      |            ^~~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:470:67: warning: 'template<class _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
  470 |     class const_mem_fun_ref_t : public boost::functional::detail::unary_function<const T&, S>
      |                                                                   ^~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/12.2.0/bits/stl_function.h:117:12: note: declared here
  117 |     struct unary_function
      |            ^~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:487:68: warning: 'template<class _Arg1, class _Arg2, class _Result> struct std::binary_function' is deprecated [-Wdeprecated-declarations]
  487 |     class const_mem_fun1_ref_t : public boost::functional::detail::binary_function<const T&, A, S>
      |                                        
                            ^~~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/12.2.0/bits/stl_function.h:131:12: note: declared here
  131 |     struct binary_function
      |            ^~~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:533:73: warning: 'template<class _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
  533 |     class pointer_to_unary_function : public boost::functional::detail::unary_function<Arg,Result>
      |                                                                         ^~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/12.2.0/bits/stl_function.h:117:12: note: declared here
  117 |     struct unary_function
      |            ^~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:557:74: warning: 'template<class _Arg1, class _Arg2, class _Result> struct std::binary_function' is deprecated [-Wdeprecated-declarations]
  557 |     class pointer_to_binary_function : public boost::functional::detail::binary_function<Arg1,Arg2,Result>
      |                                                                          ^~~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/12.2.0/bits/stl_function.h:131:12: note: declared here
  131 |     struct binary_function
      |            ^~~~~~~~~~~~~~~

In file included from C:/rtools42/ucrt64/include/c++/12.2.0/stdlib.h:36,
                 from C:/rtools42/ucrt64/lib/gcc/x86_64-w64-mingw32/12.2.0/include/mm_malloc.h:27,
                 from C:/rtools42/ucrt64/lib/gcc/x86_64-w64-mingw32/12.2.0/include/xmmintrin.h:34,
                 from C:/rtools42/ucrt64/lib/gcc/x86_64-w64-mingw32/12.2.0/include/immintrin.h:31,
                 from ../tbb_2020.3/include/tbb/machine/gcc_itsx.h:57,
                 from ../tbb_2020.3/include/tbb/machine/gcc_ia32_common.h:107,
                 from ../tbb_2020.3/include/tbb/machine/gcc_generic.h:232,
                 from ../tbb_2020.3/include/tbb/tbb_machine.h:197,
                 from ../tbb_2020.3/src/tbbmalloc/Synchronize.h:20,
                 from ../tbb_2020.3/src/tbbmalloc/Customize.h:29,
                 from ../tbb_2020.3/src/tbbmalloc/TypeDefinitions.h:54,
                 from ../tbb_2020.3/src/tbbmalloc/tbbmalloc_internal.h:21,
                 from ../tbb_2020.3/src/tbbmalloc/backend.cpp:19:
C:/rtools42/ucrt64/include/c++/12.2.0/cstdlib:137:11: error: 'at_quick_exit' has not been declared in '::'
  137 |   using ::at_quick_exit;
      |           ^~~~~~~~~~~~~

C:/rtools42/ucrt64/include/c++/12.2.0/cstdlib:160:11: error: 'quick_exit' has not been declared in '::'
  160 |   using ::quick_exit;
      |           ^~~~~~~~~~
C:/rtools42/ucrt64/include/c++/12.2.0/stdlib.h:43:14: error: 'at_quick_exit' has not been declared in 'std'
   43 |   using std::at_quick_exit;
      |              ^~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/12.2.0/stdlib.h:46:14: error: 'quick_exit' has not been declared in 'std'
   46 |   using std::quick_exit;
      |              ^~~~~~~~~~

cc1plus.exe: note: unrecognized command-line option '-Wno-unknown-warning-option' may have been intended to silence earlier diagnostics

mingw32-make[1]: *** [C:/Users/PeteS/OneDrive/St%20Andrews/Documents/.cmdstan/cmdstan-2.30.1/stan/lib/stan_math/lib/tbb_2020.3/build/Makefile.tbbmalloc:65: backend.o] Error 1

mingw32-make: *** [stan/lib/stan_math/make/libraries:173: stan/lib/stan_math/lib/tbb/tbbmalloc.def] Error 2

Error: An error occured during compilation! See the message above for more information.

I’m not sure where to proceed from here, so any help would be greatly appreciated!

Update: I tried reinstalling RTools42 to see if that would fix the problem. I now get a different error when trying to run the example model:

Compiling Stan program...
Error in `process_initialize(self, private, command, args, stdin, stdout, …`:
! Native call to `processx_exec` failed
Caused by error in `chain_call(c_processx_exec, command, c(command, args), pty, pty_options, …`:
! Command 'mingw32-make.exe' not found @win/processx.c:982 (processx_exec)
Type .Last.error to see the more details.

Update on the update: it appears that the new error occurred because I forgot to set up the C++ toolchain again after reinstalling RTools42 - I fixed this using check_cmdstan_toolchain(fix=TRUE).

Following this, I ran rebuild_cmdstan and the example mode, but it fails to compile as before.

Further update: following these threads (thread 1, thread 2) I added C:\rtools42\usr\bin and C:\rtools42\ucrt64\bin to the PATH, ran pacman -Sy mingw-w64-ucrt-x86_64-make mingw-w64-ucrt-x86_64-gcc in Powershell, and added

CXXFLAGS += -Wno-nonnull
TBB_CXXFLAGS= -U__MSVCRT_VERSION__ -D__MSVCRT_VERSION__=0x0E00

to make/local.

Unfortunately the model still fails to compile, producing the following error message:

> mod <- cmdstan_model(file)
Compiling Stan program...
INFO: Could not find files for the given pattern(s).

C:/Users/PeteS/OneDrive/St%20Andrews/Documents/.cmdstan/cmdstan-2.30.1/stan/lib/stan_math/lib/tbb_2020.3/build/Makefile.tbb:28: CONFIG: cfg=release arch=intel64 compiler=gcc target=windows runtime=mingw12.2.0

In file included from ../tbb_2020.3/src/tbb/concurrent_hash_map.cpp:17:
../tbb_2020.3/include/tbb/concurrent_hash_map.h: In constructor 'tbb::interface5::internal::hash_map_base::hash_map_base()':
../tbb_2020.3/include/tbb/concurrent_hash_map.h:131:24: warning: 'void* memset(void*, int, size_t)' clearing an object of type 'struct tbb::interface5::internal::hash_map_base::bucket' with no trivial copy-assignment; use value-initialization instead [-Wclass-memaccess]
  131 |             std::memset(my_embedded_segment, 0, sizeof(my_embedded_segment));
      |             ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../tbb_2020.3/include/tbb/concurrent_hash_map.h:93:16: note: 'struct tbb::interface5::internal::hash_map_base::bucket' declared here
   93 |         struct bucket : tbb::internal::no_copy {
      |                ^~~~~~

../tbb_2020.3/src/tbb/dynamic_link.cpp: In function 'void tbb::internal::dynamic_unlink(dynamic_link_handle)':
../tbb_2020.3/src/tbb/dynamic_link.cpp:33:39: warning: value computed is not used [-Wunused-value]
   33 |     #define dlclose( handle )       ( ! FreeLibrary( handle ) )
      |                                     ~~^~~~~~~~~~~~~~~~~~~~~~~~~
../tbb_2020.3/src/tbb/dynamic_link.cpp:418:13: note: in expansion of macro 'dlclose'
  418 |             dlclose( handle );
      |             ^~~~~~~

In file included from C:/rtools42/ucrt64/include/winnt.h:27,
                 from C:/rtools42/ucrt64/include/minwindef.h:163,
                 from C:/rtools42/ucrt64/include/windef.h:9,
                 from C:/rtools42/ucrt64/include/windows.h:69,
                 from ../tbb_2020.3/src/tbb/../rml/include/rml_base.h:25,
                 from ../tbb_2020.3/src/tbb/../rml/include/rml_tbb.h:23,
                 from ../tbb_2020.3/src/tbb/scheduler.h:25,
                 from ../tbb_2020.3/src/tbb/custom_scheduler.h:20,
                 from ../tbb_2020.3/src/tbb/scheduler.cpp:17:
In function 'long long unsigned int __readgsqword(long unsigned int)',
    inlined from '_TEB* NtCurrentTeb()' at C:/rtools42/ucrt64/include/winnt.h:9612:86,
    inlined from 'void tbb::internal::generic_scheduler::init_stack_info()' at ../tbb_2020.3/src/tbb/scheduler.cpp:169:42:
C:/rtools42/ucrt64/include/psdk_inc/intrin-impl.h:838:1: warning: array subscript 0 is outside array bounds of 'long long unsigned int [0]' [-Warray-bounds]
  838 | __buildreadseg(__readgsqword, unsigned __int64, "gs", "q")
      | ^~~~~~~~~~~~~~

In function 'long long unsigned int __readgsqword(long unsigned int)',
    inlined from '_TEB* NtCurrentTeb()' at C:/rtools42/ucrt64/include/winnt.h:9612:86,
    inlined from 'void tbb::internal::generic_scheduler::init_stack_info()' at ../tbb_2020.3/src/tbb/scheduler.cpp:169:42,
    inlined from 'static tbb::internal::generic_scheduler* tbb::internal::generic_scheduler::create_worker(tbb::internal::market&, std::size_t, bool)' at ../tbb_2020.3/src/tbb/scheduler.cpp:1281:27:
C:/rtools42/ucrt64/include/psdk_inc/intrin-impl.h:838:1: warning: array subscript 0 is outside array bounds of 'long long unsigned int [0]' [-Warray-bounds]
  838 | __buildreadseg(__readgsqword, unsigned __int64, "gs", "q")
      | ^~~~~~~~~~~~~~

In function 'long long unsigned int __readgsqword(long unsigned int)',
    inlined from '_TEB* NtCurrentTeb()' at C:/rtools42/ucrt64/include/winnt.h:9612:86,
    inlined from 'void tbb::internal::generic_scheduler::init_stack_info()' at ../tbb_2020.3/src/tbb/scheduler.cpp:169:42,
    inlined from 'static tbb::internal::generic_scheduler* tbb::internal::generic_scheduler::create_master(tbb::internal::arena*)' at ../tbb_2020.3/src/tbb/scheduler.cpp:1302:23:
C:/rtools42/ucrt64/include/psdk_inc/intrin-impl.h:838:1: warning: array subscript 0 is outside array bounds of 'long long unsigned int [0]' [-Warray-bounds]
  838 | __buildreadseg(__readgsqword, unsigned __int64, "gs", "q")
      | ^~~~~~~~~~~~~~

task.o
: duplicate section `.rdata$_ZTIN3tbb4taskE[_ZTIN3tbb4taskE]' has different size

arena.o: duplicate section `.rdata$_ZTIN3tbb4taskE[_ZTIN3tbb4taskE]' has different size

scheduler.o: duplicate section `.rdata$_ZTIN3tbb4taskE[_ZTIN3tbb4taskE]' has different size

As you can see from the part of thread2, you need to run pacman -Sy mingw-w64-ucrt-x86_64-make mingw-w64-ucrt-x86_64-gcc in Rtools 42 bash.

When I installed CmdStan on Windows 10 using R 4.2 and Rtools42, I did the following steps on Rtools 42 bash in admin mode before I ran cmdstanr::install_cmdstan() on R:

## Remove package cash
rm -rf /var/cache/pacman/pkg/*

## Reset packman key
rm -r /etc/pacman.d/gnupg/
pacman-key --init
pacman-key --populate msys2

## Update keyring package
pacman -S msys2-keyring

## Update other packages
pacman -Syyu

pacman -Sy mingw-w64-ucrt-x86_64-make mingw-w64-ucrt-x86_64-gcc
pacman -Syu mingw-w64-x86_64-make
1 Like

Update on the further update: after completing the steps above, I uninstalled cmdstanr and installed the latest development version from Github:

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

This appears to have fixed the problem - when I run a model, it now compiles and samples successfully. I have tested this with two different raw Stan models, as well as some of the ulam examples in the rethinking package. Interestingly, the ulam examples still show warning messages similar to those in my previous posts, but then proceed to sample without problem. Therefore, the problem appears to be fixed for the moment.

1 Like

Thanks for the help! I think I’ve solved the problem by re-installing cmdstanr, but if I encounter any further problems I’ll follow the steps you’ve described.

Thank you very much for providing this information @Peter.Stewart @CLRR

I have stepped through all you posted, but when I run
cmdstanr:: rebuild_cmdstan()

I got this:

Ϣ: ṩģʽ޷ҵļ
rm -f -r test
rm -f
rm -f
rm -f
rm -f
removing dependency files
rm -f
rm -f
rm -f
mingw32-make: *** No rule to make target ‘clean-libraries’, needed by ‘clean-all’. Stop.
Ϣ: ṩģʽ޷ҵļ
mingw32-make: *** No rule to make target ‘stan/src/stan/model/model_header.hpp’, needed by ‘stan/src/stan/model/model_header.hpp.gch’. Stop.
mingw32-make: *** Waiting for unfinished jobs…

— Compiling the main object file. This might take up to a minute. —
g++ -Wno-nonnull -c -o src/cmdstan/main.o src/cmdstan/main.cpp
src/cmdstan/main.cpp:1:10: fatal error: cmdstan/command.hpp: No such file or directory
1 | #include <cmdstan/command.hpp>
| ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
mingw32-make: *** [make/program:14: src/cmdstan/main.o] Error 1

Many thanks for any possible solutions!!