Problem installing cmdstan with R4.2 and RTools42

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