RStan build failure on MS-Win 10

Makevars.win seems to be ignored and igraph won’t build.

I updated R and RStudio to the latest versions, 4.1.2 and 2021.09.1-372, respectively, and then followed RStan Getting Started · stan-dev/rstan Wiki · GitHub. Since Sys.getenv(“HOME”) return my user root directory, not the documents folder, I put the .R directory under the former and created Makevars.win, including a leading newline and space before the macro definition.

Makevars.win

Makevars.win seemed to be ignored, or possibly it didn’t matter. Typical compilation:

"J:/rtools40/mingw32/bin/"gcc  -I"J:/Programs/R-4.1.2/include" -DNDEBUG -I/mingw32/include/libxml2 -I/mingw32/include -DLIBXML_STATIC -DUSING_R -DHAVE_FMEMOPEN=0 -DHAVE_OPEN_MEMSTREAM=0 -DHAVE_RINTF -DWin32 -DHAVE_LIBXML=1 -DHAVE_UNISTD_H -Wall -DPACKAGE_VERSION=\"1.2.11\" -DHAVE_FMIN=1 -DHAVE_LOG2=1 -DHAVE_SNPRINTF -DHAVE_GFORTRAN -Ics -I/mingw32/include -DHAVE_GLPK=1 -Iplfit -Iprpack -DIGRAPH_THREAD_LOCAL= -DPRPACK_IGRAPH_SUPPORT -I. -Iinclude -ISuiteSparse_config -DNDEBUG -DNPARTITION -DNTIMER -DNCAMD -DNPRINT -I/mingw32/include -DINTERNAL_SUITESPARSE -DINTERNAL_ARPACK         -O2 -Wall  -std=gnu99 -mfpmath=sse -msse2 -mstackrealign  -c components.c -o components.o

The std=gnu99 or gnu++11 in other places suggests it’s not using C++ 14, in which case I presume the settings for CXX14FLAGS is irrelevant.

igraph

At the start the console log indicated the source version was newer than the binary version, and it attempted to build the newer version from source. It ended with

"J:/rtools40/mingw32/bin/"gcc  -I"J:/Programs/R-4.1.2/include" -DNDEBUG -I/mingw32/include/libxml2 -I/mingw32/include -DLIBXML_STATIC -DUSING_R -DHAVE_FMEMOPEN=0 -DHAVE_OPEN_MEMSTREAM=0 -DHAVE_RINTF -DWin32 -DHAVE_LIBXML=1 -DHAVE_UNISTD_H -Wall -DPACKAGE_VERSION=\"1.2.11\" -DHAVE_FMIN=1 -DHAVE_LOG2=1 -DHAVE_SNPRINTF -DHAVE_GFORTRAN -Ics -I/mingw32/include -DHAVE_GLPK=1 -Iplfit -Iprpack -DIGRAPH_THREAD_LOCAL= -DPRPACK_IGRAPH_SUPPORT -I. -Iinclude -ISuiteSparse_config -DNDEBUG -DNPARTITION -DNTIMER -DNCAMD -DNPRINT -I/mingw32/include -DINTERNAL_SUITESPARSE -DINTERNAL_ARPACK         -O2 -Wall  -std=gnu99 -mfpmath=sse -msse2 -mstackrealign  -c fast_community.c -o fast_community.o
fast_community.c:261:13: warning: 'igraph_i_fastgreedy_community_list_check_heap' defined but not used [-Wunused-function]
 static void igraph_i_fastgreedy_community_list_check_heap(
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"J:/rtools40/mingw32/bin/"gcc  -I"J:/Programs/R-4.1.2/include" -DNDEBUG -I/mingw32/include/libxml2 -I/mingw32/include -DLIBXML_STATIC -DUSING_R -DHAVE_FMEMOPEN=0 -DHAVE_OPEN_MEMSTREAM=0 -DHAVE_RINTF -DWin32 -DHAVE_LIBXML=1 -DHAVE_UNISTD_H -Wall -DPACKAGE_VERSION=\"1.2.11\" -DHAVE_FMIN=1 -DHAVE_LOG2=1 -DHAVE_SNPRINTF -DHAVE_GFORTRAN -Ics -I/mingw32/include -DHAVE_GLPK=1 -Iplfit -Iprpack -DIGRAPH_THREAD_LOCAL= -DPRPACK_IGRAPH_SUPPORT -I. -Iinclude -ISuiteSparse_config -DNDEBUG -DNPARTITION -DNTIMER -DNCAMD -DNPRINT -I/mingw32/include -DINTERNAL_SUITESPARSE -DINTERNAL_ARPACK         -O2 -Wall  -std=gnu99 -mfpmath=sse -msse2 -mstackrealign  -c feedback_arc_set.c -o feedback_arc_set.o
In file included from feedback_arc_set.c:31:
igraph_glpk_support.h:36:10: fatal error: glpk.h: No such file or directory
 #include <glpk.h>
          ^~~~~~~~
compilation terminated.
make: *** [J:/Programs/R-4.1.2/etc/i386/Makeconf:238: feedback_arc_set.o] Error 1
ERROR: compilation failed for package 'igraph'

I presume igraph is not under stan developers’ control, but I still need a way to build the package in the face of this.

Other

It’s odd that most of the builds seem to be 32 bit; my hardware, OS, RStudio are all 64 bit. I think R installs both 32 and 64 bit versions. The log does show some sections that say *** arch - x64.

There are various other warnings.

Contents of .R/Makevars

Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
  cannot open file 'C:\Users\rdboylan/.R/Makevars': No such file or directory
> writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars.win")))

 CXX14FLAGS += -mtune=native -O3 -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2"
Error in loadNamespace(x) : there is no package called ‘devtools’
> install.packages("devtools")
also installing the dependencies ‘credentials’, ‘zip’, ‘gitcreds’, ‘ini’, ‘diffobj’, ‘gert’, ‘gh’, ‘whisker’, ‘xopen’, ‘brew’, ‘brio’, ‘praise’, ‘waldo’, ‘usethis’, ‘memoise’, ‘pkgload’, ‘rcmdcheck’, ‘remotes’, ‘roxygen2’, ‘rversions’, ‘sessioninfo’, ‘testthat’


  There is a binary version available but the source version is later:
     binary source needs_compilation
gert  1.4.3  1.5.0              TRUE  # I said use the binary
# tons of setup

> devtools::session_info("rstan")
- Session info -------------------------------------------------------------------------------------------------------------------------------------------------
 setting  value
 version  R version 4.1.2 (2021-11-01)
 os       Windows Server x64 (build 17763)
 system   x86_64, mingw32
 ui       RStudio
 language (EN)
 collate  English_United States.1252
 ctype    English_United States.1252
 tz       America/Los_Angeles
 date     2022-01-05
 rstudio  2021.09.1+372 Ghost Orchid (desktop)
 pandoc   2.14.0.3 @ J:/Programs/RStudio/bin/pandoc/ (via rmarkdown)

- Packages -----------------------------------------------------------------------------------------------------------------------------------------------------
 package      * version   date (UTC) lib source
 backports      1.4.1     2021-12-13 [1] CRAN (R 4.1.2)
 BH             1.78.0-0  2021-12-15 [1] CRAN (R 4.1.2)
 callr          3.7.0     2021-04-20 [1] CRAN (R 4.1.2)
 checkmate      2.0.0     2020-02-06 [1] CRAN (R 4.1.2)
 cli            3.1.0     2021-10-27 [1] CRAN (R 4.1.2)
 colorspace     2.0-2     2021-06-24 [1] CRAN (R 4.1.2)
 crayon         1.4.2     2021-10-29 [1] CRAN (R 4.1.2)
 desc           1.4.0     2021-09-28 [1] CRAN (R 4.1.2)
 digest         0.6.29    2021-12-01 [1] CRAN (R 4.1.2)
 ellipsis       0.3.2     2021-04-29 [1] CRAN (R 4.1.2)
 fansi          0.5.0     2021-05-25 [1] CRAN (R 4.1.2)
 farver         2.1.0     2021-02-28 [1] CRAN (R 4.1.2)
 ggplot2      * 3.3.5     2021-06-25 [1] CRAN (R 4.1.2)
 glue           1.6.0     2021-12-17 [1] CRAN (R 4.1.2)
 gridExtra      2.3       2017-09-09 [1] CRAN (R 4.1.2)
 gtable         0.3.0     2019-03-25 [1] CRAN (R 4.1.2)
 inline         0.3.19    2021-05-31 [1] CRAN (R 4.1.2)
 isoband        0.2.5     2021-07-13 [1] CRAN (R 4.1.2)
 labeling       0.4.2     2020-10-20 [1] CRAN (R 4.1.1)
 lattice        0.20-45   2021-09-22 [1] CRAN (R 4.1.2)
 lifecycle      1.0.1     2021-09-24 [1] CRAN (R 4.1.2)
 loo            2.4.1     2020-12-09 [1] CRAN (R 4.1.2)
 magrittr       2.0.1     2020-11-17 [1] CRAN (R 4.1.2)
 MASS           7.3-54    2021-05-03 [1] CRAN (R 4.1.2)
 Matrix         1.4-0     2021-12-08 [1] CRAN (R 4.1.2)
 matrixStats    0.61.0    2021-09-17 [1] CRAN (R 4.1.2)
 mgcv           1.8-38    2021-10-06 [1] CRAN (R 4.1.2)
 munsell        0.5.0     2018-06-12 [1] CRAN (R 4.1.2)
 nlme           3.1-153   2021-09-07 [1] CRAN (R 4.1.2)
 pillar         1.6.4     2021-10-18 [1] CRAN (R 4.1.2)
 pkgbuild       1.3.1     2021-12-20 [1] CRAN (R 4.1.2)
 pkgconfig      2.0.3     2019-09-22 [1] CRAN (R 4.1.2)
 prettyunits    1.1.1     2020-01-24 [1] CRAN (R 4.1.2)
 processx       3.5.2     2021-04-30 [1] CRAN (R 4.1.2)
 ps             1.6.0     2021-02-28 [1] CRAN (R 4.1.2)
 R6             2.5.1     2021-08-19 [1] CRAN (R 4.1.2)
 RColorBrewer   1.1-2     2014-12-07 [1] CRAN (R 4.1.1)
 Rcpp           1.0.7     2021-07-07 [1] CRAN (R 4.1.2)
 RcppEigen      0.3.3.9.1 2020-12-17 [1] CRAN (R 4.1.2)
 RcppParallel   5.1.5     2022-01-05 [1] CRAN (R 4.1.2)
 rlang          0.4.12    2021-10-18 [1] CRAN (R 4.1.2)
 rprojroot      2.0.2     2020-11-15 [1] CRAN (R 4.1.2)
 rstan        * 2.21.3    2021-12-19 [1] CRAN (R 4.1.2)
 scales         1.1.1     2020-05-11 [1] CRAN (R 4.1.2)
 StanHeaders  * 2.21.0-7  2020-12-17 [1] CRAN (R 4.1.2)
 tibble         3.1.6     2021-11-07 [1] CRAN (R 4.1.2)
 utf8           1.2.2     2021-07-24 [1] CRAN (R 4.1.2)
 vctrs          0.3.8     2021-04-29 [1] CRAN (R 4.1.2)
 viridisLite    0.4.0     2021-04-13 [1] CRAN (R 4.1.2)
 withr          2.4.3     2021-11-30 [1] CRAN (R 4.1.2)

 [1] J:/Programs/R-4.1.2/library

--

If you install igraph as a binary (not from source), are you able to install rstan?

If you’d like to install igraph from source, you need to install its dependencies in Rtools:

pacman -Sy --noconfirm mingw-w64-i686-glpk mingw-w64-i686-libxml2 mingw-w64-i686-gmp mingw-w64-x86_64-glpk mingw-w64-x86_64-libxml2 mingw-w64-x86_64-gmp

Then, try to install rstan.

I installed igraph from binary and the rstan install then went very smoothly, perhaps too smoothly. But it fails the test.

Restarting R session...

> install.packages("rstan", repos = "https://cloud.r-project.org/", dependencies = TRUE)
trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.1/rstan_2.21.3.zip'
Content type 'application/zip' length 5241912 bytes (5.0 MB)
downloaded 5.0 MB

package ‘rstan’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
	C:\Users\rdboylan\AppData\Local\Temp\2\Rtmp4AUe21\downloaded_packages
> example(stan_model, package = "rstan", run.dontrun = TRUE)
# lots of output, including 2 program listings, ending in 
Compilation ERROR, function(s)/method(s) not created!
Error in compileCode(f, code, language = language, verbose = verbose) : 
  sh: -c: line 1: unexpected EOF while looking for matching `"'sh: -c: line 2: syntax error: unexpected end of filemake: *** [J:/Programs/R-4.1.2/etc/x64/Makeconf:245: file4cdc35b67421.o] Error 2

Here are some excerpts from the log of the test:

make cmd is
  make -f "J:/Programs/R-4.1.2/etc/x64/Makeconf" -f "J:/Programs/R-4.1.2/share/make/winshlib.mk" -f "C:/Users/rdboylan/.R/Makevars.win" CXX='$(CXX14) $(CXX14STD)' CXXFLAGS='$(CXX14FLAGS)' CXXPICFLAGS='$(CXX14PICFLAGS)' SHLIB_LDFLAGS='$(SHLIB_CXX14LDFLAGS)' SHLIB_LD='$(SHLIB_CXX14LD)' SHLIB="file4cdc35b67421.dll" WIN=64 TCLBIN=64 OBJECTS="file4cdc35b67421.o"

make would use
"J:/rtools40/mingw64/bin/"g++  -std=gnu++14 -I"J:/Programs/R-4.1.2/include" -DNDEBUG   -I"J:/Programs/R-4.1.2/library/Rcpp/include/"  -I"J:/Programs/R-4.1.2/library/RcppEigen/include/"  -I"J:/Programs/R-4.1.2/library/RcppEigen/include/unsupported"  -I"J:/Programs/R-4.1.2/library/BH/include" -I"J:/Programs/R-4.1.2/library/StanHeaders/include/src/"  -I"J:/Programs/R-4.1.2/library/StanHeaders/include/"  -I"J:/Programs/R-4.1.2/library/RcppParallel/include/"  -I"J:/Programs/R-4.1.2/library/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DBOOST_NO_AUTO_PTR  -include "J:/Programs/R-4.1.2/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp"  -std=c++1y         -O2 -Wall  -mfpmath=sse -msse2 -mstackrealign  -mtune=native -O3 -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2" -c file4cdc35b67421.cpp -o file4cdc35b67421.o
if test "zfile4cdc35b67421.o" != "z"; then \
  if test -e "file4cdc35b67421-win.def"; then \
    echo "J:/rtools40/mingw64/bin/"g++  -shared -s -static-libgcc -o file4cdc35b67421.dll file4cdc35b67421-win.def file4cdc35b67421.o   "J:/Programs/R-4.1.2/library/rstan/lib/x64/libStanServices.a" -L"J:/Programs/R-4.1.2/library/StanHeaders/libs/x64" -lStanHeaders -L"J:/Programs/R-4.1.2/library/RcppParallel/lib/x64" -ltbb  -L"J:/Programs/R-4.1.2/bin/x64" -lR ; \
    "J:/rtools40/mingw64/bin/"g++  -shared -s -static-libgcc -o file4cdc35b67421.dll file4cdc35b67421-win.def file4cdc35b67421.o   "J:/Programs/R-4.1.2/library/rstan/lib/x64/libStanServices.a" -L"J:/Programs/R-4.1.2/library/StanHeaders/libs/x64" -lStanHeaders -L"J:/Programs/R-4.1.2/library/RcppParallel/lib/x64" -ltbb  -L"J:/Programs/R-4.1.2/bin/x64" -lR ; \
  else \
    echo EXPORTS > tmp.def; \
    "J:/rtools40/mingw64/bin/"nm file4cdc35b67421.o | sed -n 's/^.* [BCDRT] / /p' | sed -e '/[.]refptr[.]/d' -e '/[.]weak[.]/d' | sed 's/[^ ][^ ]*/"&"/g'  >> tmp.def; \
    echo "J:/rtools40/mingw64/bin/"g++  -shared -s -static-libgcc -o file4cdc35b67421.dll tmp.def file4cdc35b67421.o   "J:/Programs/R-4.1.2/library/rstan/lib/x64/libStanServices.a" -L"J:/Programs/R-4.1.2/library/StanHeaders/libs/x64" -lStanHeaders -L"J:/Programs/R-4.1.2/library/RcppParallel/lib/x64" -ltbb  -L"J:/Programs/R-4.1.2/bin/x64" -lR ; \
    "J:/rtools40/mingw64/bin/"g++  -shared -s -static-libgcc -o file4cdc35b67421.dll tmp.def file4cdc35b67421.o   "J:/Programs/R-4.1.2/library/rstan/lib/x64/libStanServices.a" -L"J:/Programs/R-4.1.2/library/StanHeaders/libs/x64" -lStanHeaders -L"J:/Programs/R-4.1.2/library/RcppParallel/lib/x64" -ltbb  -L"J:/Programs/R-4.1.2/bin/x64" -lR ; \
    rm -f tmp.def; \
  fi \
fi

ERROR(s) during compilation: source code errors or compiler configuration errors!

It looks as if the CXX14FLAGS from Makevars.win are finally making an appearance. But the first option is -mtune=native which doesn’t literally contradict the last line of the instructions below, but seems uncomfortably close.

> example(stan_model, package = "rstan", run.dontrun = TRUE)
Loading required package: StanHeaders
Loading required package: ggplot2
rstan (Version 2.21.3, GitRev: 2e1f913d3ca3)
For execution on a local, multicore CPU with excess RAM we recommend calling
options(mc.cores = parallel::detectCores()).
To avoid recompilation of unchanged Stan programs, we recommend calling
rstan_options(auto_write = TRUE)
Do not specify '-march=native' in 'LOCAL_CPPFLAGS' or a Makevars fil

Are you able to install other packages from source? For example:

install.packages('jsonlite', type='source')

And are you able to compile c++?

Rcpp::sourceCpp(code='
  #include <Rcpp.h>

  // [[Rcpp::export]]
  int fibonacci(const int x) {
    if (x == 0) return(0);
    if (x == 1) return(1);
    return (fibonacci(x - 1)) + fibonacci(x - 2);
  }'
)

jsonlite build fails, with somewhat bizarre mentions of stan. It is in the same session in which I tried to use stan. Here’s the end of the compilation log:

"J:/rtools40/mingw32/bin/"ar rcs yajl/libstatyajl.a yajl/yajl.o yajl/yajl_alloc.o yajl/yajl_buf.o yajl/yajl_encode.o yajl/yajl_gen.o yajl/yajl_lex.o yajl/yajl_parser.o yajl/yajl_tree.o
J:/rtools40/mingw32/bin/gcc -shared -s -static-libgcc -o jsonlite.dll tmp.def base64.o collapse_array.o collapse_object.o collapse_pretty.o escape_chars.o integer64_to_na.o is_datelist.o is_recordlist.o is_scalarlist.o modp_numtoa.o null_to_na.o num_to_char.o parse.o prettify.o push_parser.o r-base64.o register.o row_collapse.o transpose_list.o validate.o -Lyajl -lstatyajl J:/Programs/R-4.1.2/library/rstan/lib/x64/libStanServices.a -LJ:/Programs/R-4.1.2/library/StanHeaders/libs/x64 -lStanHeaders -LJ:/Programs/R-4.1.2/library/RcppParallel/lib/x64 -ltbb -LJ:/Programs/R-4.1.2/bin/i386 -lR
J:/Programs/R-4.1.2/library/StanHeaders/libs/x64/StanHeaders.dll: file not recognized: file format not recognized
collect2.exe: error: ld returned 1 exit status
no DLL was created
ERROR: compilation failed for package 'jsonlite'
* removing 'J:/Programs/R-4.1.2/library/jsonlite'
* restoring previous 'J:/Programs/R-4.1.2/library/jsonlite'
Warning in install.packages :
  installation of package ‘jsonlite’ had non-zero exit status

The Rcpp::sourceCpp seems to have worked; it executed without errors and I see a fibonacci function in the environment display of RStudio.

In a fresh, plain 64-bit R (not RStudio) session, jsonlite builds for 32 and 64 bit without complaint.

1 Like

I tried removing the package and going again. But the end result was

*** arch - i386
"J:/rtools40/mingw32/bin/"g++  -std=gnu++14 -I"J:/Programs/R-4.1.2/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 -DSTAN_THREADS -DRCPP_PARALLEL_USE_TBB=1 -I'J:/Programs/R-4.1.2/library/Rcpp/include' -I'J:/Programs/R-4.1.2/library/RcppEigen/include' -I'J:/Programs/R-4.1.2/library/BH/include' -I'J:/Programs/R-4.1.2/library/StanHeaders/include' -I'J:/Programs/R-4.1.2/library/RcppParallel/include'     -DRCPP_PARALLEL_USE_TBB=1   -O2 -Wall  -mfpmath=sse -msse2 -mstackrealign  -mtune=native -O3 -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2" -c sparse_extractors.cpp -o sparse_extractors.o
sh: -c: line 1: unexpected EOF while looking for matching `"'
sh: -c: line 2: syntax error: unexpected end of file
make: *** [J:/Programs/R-4.1.2/etc/i386/Makeconf:245: sparse_extractors.o] Error 2
ERROR: compilation failed for package 'rstan'
* removing 'J:/Programs/R-4.1.2/library/rstan'
* restoring previous 'J:/Programs/R-4.1.2/library/rstan'
  1. The problem looking for matching " does not seem to be with the first printed line; all the " look balanced to me. The use of "J:/rtools40/mingw32/bin/"g++ looks funny, but plenty of earlier compilations had that without error.
  2. I was doing parallel compiles, but the line shown seems to be the only one active in this section.

Fuller History

Using 64 bit vanilla R throughout and following RStan Getting Started · stan-dev/rstan Wiki · GitHub.

Removed rstan and verified no .RData file. Restarted.

Binary build

> install.packages("rstan", repos = "https://cloud.r-project.org/", dependencies = TRUE)
trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.1/rstan_2.21.3.zip'
Content type 'application/zip' length 5241778 bytes (5.0 MB)
downloaded 5.0 MB

package ‘rstan’ successfully unpacked and MD5 sums checked

> example(stan_model, package = "rstan", run.dontrun = TRUE)
Loading required package: StanHeaders
Loading required package: ggplot2
rstan (Version 2.21.3, GitRev: 2e1f913d3ca3)
# output, including program listings, deleted

Compilation ERROR, function(s)/method(s) not created!
Error in compileCode(f, code, language = language, verbose = verbose) : 
  sh: -c: line 1: unexpected EOF while looking for matching `"'sh: -c: line 2: syntax error: unexpected end of filemake: *** [J:/Programs/R-4.1.2/etc/x64/Makeconf:245: file5de038ef1c06.o] Error 2

That is not exactly the error given in the installation instructions, but I followed their next step to do a source build. Restarted R first.

Source Build

> parallel::detectCores()
[1] 20
> # Compile packages using all cores
> Sys.setenv(MAKEFLAGS = paste0("-j",parallel::detectCores()))
> date(); install.packages(c("StanHeaders","rstan"),type="source"); date()
[1] "Mon Jan 10 10:47:58 2022"
--- Please select a CRAN mirror for use in this session ---
trying URL 'https://ftp.osuosl.org/pub/cran/src/contrib/StanHeaders_2.21.0-7.tar.gz'
Content type 'application/x-gzip' length 1402572 bytes (1.3 MB)
downloaded 1.3 MB

trying URL 'https://ftp.osuosl.org/pub/cran/src/contrib/rstan_2.21.3.tar.gz'
Content type 'application/x-gzip' length 1163545 bytes (1.1 MB)
downloaded 1.1 MB

* installing *source* package 'StanHeaders' ...
** package 'StanHeaders' successfully unpacked and MD5 sums checked
** using staged installation
** libs
# builds for i386 and x64
# various warnings about unused or uninitialized variables
J:/rtools40/mingw64/bin/gcc -shared -s -static-libgcc -o StanHeaders.dll tmp.def cvodes/cvodes_nls_stg1.o cvodes/cvodes_nls_sim.o cvodes/cvodes_ls.o cvodes/cvodea_io.o cvodes/cvodes_spils.o cvodes/cvodes.o cvodes/cvodes_bandpre.o cvodes/cvodes_bbdpre.o cvodes/cvodes_nls_stg.o cvodes/cvodea.o cvodes/cvodes_io.o cvodes/cvodes_direct.o cvodes/cvodes_diag.o cvodes/cvodes_nls.o sundials/sundials_sparse.o sundials/sundials_dense.o sundials/sundials_nvector_senswrapper.o sundials/sundials_nvector.o sundials/sundials_pcg.o sundials/sundials_math.o sundials/sundials_sptfqmr.o sundials/sundials_mpi.o sundials/sundials_linearsolver.o sundials/sundials_iterative.o sundials/sundials_spbcgs.o sundials/sundials_band.o sundials/sundials_version.o sundials/sundials_nonlinearsolver.o sundials/sundials_direct.o sundials/sundials_matrix.o sunmatrix/band/sunmatrix_band.o sunmatrix/dense/sunmatrix_dense.o sunlinsol/band/sunlinsol_band.o sunlinsol/dense/sunlinsol_dense.o sunnonlinsol/newton/sunnonlinsol_newton.o sunnonlinsol/fixedpoint/sunnonlinsol_fixedpoint.o idas/idas_nls.o idas/idas_nls_sim.o idas/idas_ls.o idas/idas.o idas/idas_bbdpre.o idas/idas_nls_stg.o idas/idaa_io.o idas/idas_direct.o idas/idas_io.o idas/idaa.o idas/idas_ic.o idas/idas_spils.o nvector/serial/nvector_serial.o init.o -LJ:/Programs/R-4.1.2/bin/x64 -lR
installing via 'install.libs.R' to J:/Programs/R-4.1.2/library/00LOCK-StanHeaders/00new/StanHeaders
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
  converting help for package 'StanHeaders'
    finding HTML links ... done
    CxxFlags                                html  
    stanFunction                            html  
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
*** arch - i386
*** arch - x64
** testing if installed package can be loaded from final location
*** arch - i386
*** arch - x64
** testing if installed package keeps a record of temporary installation path
* DONE (StanHeaders)
Making 'packages.html' ... done
* installing *source* package 'rstan' ...
** package 'rstan' successfully unpacked and MD5 sums checked
** using staged installation
** libs

*** arch - i386
"J:/rtools40/mingw32/bin/"g++  -std=gnu++14 -I"J:/Programs/R-4.1.2/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 -DSTAN_THREADS -DRCPP_PARALLEL_USE_TBB=1 -I'J:/Programs/R-4.1.2/library/Rcpp/include' -I'J:/Programs/R-4.1.2/library/RcppEigen/include' -I'J:/Programs/R-4.1.2/library/BH/include' -I'J:/Programs/R-4.1.2/library/StanHeaders/include' -I'J:/Programs/R-4.1.2/library/RcppParallel/include'     -DRCPP_PARALLEL_USE_TBB=1   -O2 -Wall  -mfpmath=sse -msse2 -mstackrealign  -mtune=native -O3 -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2" -c sparse_extractors.cpp -o sparse_extractors.o
sh: -c: line 1: unexpected EOF while looking for matching `"'
sh: -c: line 2: syntax error: unexpected end of file
make: *** [J:/Programs/R-4.1.2/etc/i386/Makeconf:245: sparse_extractors.o] Error 2
ERROR: compilation failed for package 'rstan'
* removing 'J:/Programs/R-4.1.2/library/rstan'
* restoring previous 'J:/Programs/R-4.1.2/library/rstan'

It looks as if it built StanHeaders OK but failed one the first attempted compilation for RStan.

I take that back: toward the very end of the line is -msse4.2". Which is not balanced and the result of a stray character in my Makevars.win. I’ll report the results after cleanup.

With the stray " in Makevars.win removed, StanHeaders and rstan built from source and the test example ran without errors (at least that I saw). There were quite a few warnings.

Lessons:

  1. Random characters in your control files are undesirable :)
  2. Study the logs carefully.
  3. Maybe use a binary of an older version of a package (igraph) if the newer source won’t build. It seems quite possible that the only reason it didn’t build was point 1.

Thanks to @andrjohns and @hsbadr for their help.