Trouble following rstantools vignette

Short summary of the problem
R hanging after trying to run pkgbuild::compile_dll()

I have an R package that uses rstan and I have been working to learn how to follow the suggested guidelines using rstantools. A few months ago, I worked through the vignette at 

https://mc-stan.org/rstantools/articles/minimal-rstan-package.html#documentation

and created and ran the rstanlm package there. 

I am now back to this but this time I cannot get it to work. When I give the command (from the vignette) 

 pkgbuild::compile_dll()

all of the compilations are done, but then R hangs on the command

 C:/rtools40/mingw64/bin/g++ -shared -s -static-libgcc -o rstanlm.dll tmp.def RcppExports.o stanExports_lm.o -LC:/R/win-library/4.1/RcppParallel/lib/x64 -ltbb -ltbbmalloc -LC:/R/win-library/4.1/RcppParallel/lib/x64 -Wl,-rpath,C:/R/win-library/4.1/RcppParallel/lib/x64 -ltbb -ltbbmalloc -LC:/PROGRA~1/R/R-41~1.1/bin/x64 -lR

with 

C:\rtools40\mingw64\x86_64-w64-mingw32\bin\ld.exe  

running.  What am I missing?

I have tried this with R 4.1.1 and 4.1.2.

Relatedly in the vignette,  the next command is

roxygen2::roxygenize()

and the output from that in the vignette has errors. Are those to be ignored?

Eventually (perhaps after an hour), the process stopped and this is what I see, but does not give me a clue.

C:/rtools40/mingw64/bin/…/lib/gcc/x86_64-w64-mingw32/8.3.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: stanExports_lm.o:stanExports_lm.cc:(.data$__emutls_v._ZZN4stan4math22AutodiffStackSingletonINS0_4variENS0_15chainable_allocEE4initEvE14is_initialized+0x18): undefined reference to `__emutls_t._ZZN4stan4math22AutodiffStackSingletonINS0_4variENS0_15chainable_allocEE4initEvE14is_initialized’
collect2.exe: error: ld returned 1 exit status
no DLL was created
ERROR: compilation failed for package ‘rstanlm’

  • removing ‘C:/Users/wqmeeker/AppData/Local/Temp/Rtmps9xqtK/devtools_install_26471cc4ae7/rstanlm’

Error in (function (command = NULL, args = character(), error_on_status = TRUE, :
System command ‘Rcmd.exe’ failed, exit status: 1, stdout + stderr (last 10 lines):
E> C:/rtools40/mingw64/bin/…/lib/gcc/x86_64-w64-mingw32/8.3.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: stanExports_lm.o:stanExports_lm.cc:(.text$_ZN5Eigen7MapBaseINS_5BlockINS_9TransposeINS_6MatrixIdLi1ELin1ELi1ELi1ELin1EEEEELin1ELi1ELb1EEELi0EEC2EPdxx+0x1d): undefined reference to Eigen::MatrixBase<Eigen::Block<Eigen::Transpose<Eigen::Matrix<double, 1, -1, 1, 1, -1> >, -1, 1, true> >::MatrixBase()' E> C:/rtools40/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: stanExports_lm.o:stanExports_lm.cc:(.text$_ZN5Eigen7MapBaseINS_5BlockINS_9TransposeINS_6MatrixIdLi1ELin1ELi1ELi1ELin1EEEEELin1ELi1ELb1EEELi0EEC2EPdxx+0x5e): undefined reference to void Eigen::MapBase<Eigen::Block<Eigen::Transpose<Eigen::Matrix<double, 1, -1, 1, 1, -1> >, -1, 1, true>, 0>::checkSanity<Eigen::Block<Eigen::Transpose<Ee[0m
[…]
Type .Last.error.trace to see where the error occu

.Last.error.trace

Stack trace:

  1. pkgbuild::compile_dll()
  2. withr::with_makevars(compiler_flags(debug), assignment = “+=”, …
  3. withr:::with_envvar(c(R_MAKEVARS_USER = makevars_file), { …
  4. base:::force(code)
  5. base:::force(code)
  6. pkgbuild:::install_min(path, dest = install_dir, components = “libs”, …
  7. pkgbuild:::rcmd_build_tools(“INSTALL”, c(path, paste("–library=", …
  8. pkgbuild:::with_build_tools(callr::rcmd_safe(…, env = env, …
  9. withr::with_path(rtools_path(), code)
  10. base:::force(code)
  11. callr::rcmd_safe(…, env = env, spinner = FALSE, show = FALSE, …
  12. callr:::run_r(options)
  13. base:::with(options, with_envvar(env, do.call(processx::run, …
  14. base:::with.default(options, with_envvar(env, do.call(processx::run, …
  15. base:::eval(substitute(expr), data, enclos = parent.frame())
  16. base:::eval(substitute(expr), data, enclos = parent.frame())
  17. callr:::with_envvar(env, do.call(processx::run, c(list(bin, args = real_cmd …
  18. base:::force(code)
  19. base:::do.call(processx::run, c(list(bin, args = real_cmdargs, …
  20. (function (command = NULL, args = character(), error_on_status = TRUE, …
  21. throw(new_process_error(res, call = sys.call(), echo = echo, …

x System command ‘Rcmd.exe’ failed, exit status: 1, stdout + stderr (last 10 lines):
E> C:/rtools40/mingw64/bin/…/lib/gcc/x86_64-w64-mingw32/8.3.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: stanExports_lm.o:stanExports_lm.cc:(.text$_ZN5Eigen7MapBaseINS_5BlockINS_9TransposeINS_6MatrixIdLi1ELin1ELi1ELi1ELin1EEEEELin1ELi1ELb1EEELi0EEC2EPdxx+0x1d): undefined reference to Eigen::MatrixBase<Eigen::Block<Eigen::Transpose<Eigen::Matrix<double, 1, -1, 1, 1, -1> >, -1, 1, true> >::MatrixBase()' E> C:/rtools40/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: stanExports_lm.o:stanExports_lm.cc:(.text$_ZN5Eigen7MapBaseINS_5BlockINS_9TransposeINS_6MatrixIdLi1ELin1ELi1ELi1ELin1EEEEELin1ELi1ELb1EEELi0EEC2EPdxx+0x5e): undefined reference to void Eigen::MapBase<Eigen::Block<Eigen::Transpose<Eigen::Matrix<double, 1, -1, 1, 1, -1> >, -1, 1, true>, 0>::checkSanity<Eigen::Block<Eigen::Transpose<Eigen::Matrix<double, 1, -1, 1, 1, -1> >, -1, 1, true> >(Eigen::internal::enable_if<Eigen::internal::traits<Eigen::Block<Eigen::Transpose<Eigen::Matrix<double, 1, -1, 1, 1, -1> >, -1, 1, true> >::Alignment==(0), void*>::type) const’
E> C:/rtools40/mingw64/bin/…/lib/gcc/x86_64-w64-mingw32/8.3.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: stanExports_lm.o:stanExports_lm.cc:(.text$_ZN5Eigen8internal31generic_dense_assignment_kernelINS0_9evaluatorINS_6MatrixIdLi1ELin1ELi1ELi1ELin1EEEEENS2_INS_14CwiseNullaryOpINS0_18scalar_constant_opIdEES4_EEEENS0_9assign_opIddEELi0EE12assignPacketILi16ELi16EDv2_dEEvx+0x2e): undefined reference to double __vector(2) Eigen::internal::evaluator<Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, Eigen::Matrix<double, 1, -1, 1, 1, -1> > >::packet<16, double __vector(2), long long>(long long) const' E> C:/rtools40/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: stanExports_lm.o:stanExports_lm.cc:(.text$_ZN5Eigen8internal31unaligned_dense_assignment_loopILb0EE3runINS0_31generic_dense_assignment_kernelINS0_9evaluatorINS_6MatrixIdLi1ELin1ELi1ELi1ELin1EEEEENS5_INS_14CwiseNullaryOpINS0_18scalar_constant_opIdEES7_EEEENS0_9assign_opIddEELi0EEEEEvRT_xx+0x32): undefined reference to Eigen::internal::generic_dense_assignment_kernel<Eigen::internal::evaluator<Eigen::Matrix<double, 1, -1, 1, 1, -1> >, Eigen::internal::evaluator<Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op, Eigen::Matrix<double, 1, -1, 1, 1, -1> > >, Eigen::internal::assign_op<double, double>, 0>::assignCoeff(long long)’
E> C:/rtools40/mingw64/bin/…/lib/gcc/x86_64-w64-mingw32/8.3.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: stanExports_lm.o:stanExports_lm.cc:(.text$_ZN5Eigen8internal31generic_dense_assignment_kernelINS0_9evaluatorINS_6MatrixIdLi1ELin1ELi1ELi1ELin1EEEEENS2_INS_14CwiseNullaryOpINS0_18scalar_constant_opIdEES4_EEEENS0_9assign_opIddEELi0EE11assignCoeffEx+0x2e): undefined reference to double Eigen::internal::evaluator<Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, Eigen::Matrix<double, 1, -1, 1, 1, -1> > >::coeff<long long>(long long) const' E> C:/rtools40/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: stanExports_lm.o:stanExports_lm.cc:(.data$__emutls_v._ZZN4stan4math22AutodiffStackSingletonINS0_4variENS0_15chainable_allocEE4initEvE14is_initialized+0x18): undefined reference to __emutls_t._ZZN4stan4math22AutodiffStackSingletonINS0_4variENS0_15chainable_allocEE4initEvE14is_initialized’
E> collect2.exe: error: ld returned 1 exit status
E> no DLL was created
E> ERROR: compilation failed for package ‘rstanlm’
E> * removing ‘C:/Users/wqmeeker/AppData/Local/Temp/Rtmps9xqtK/devtools_install_26471cc4ae7/rstanlm’