Collect2.exe: error: ld returned 1 exit status on Windows 10, R 4.0.2

I’ve been getting many, many different problems with rstan since I updated Microsoft R Open to 4.02, but after much trial and error (and error, and error…) I think this is now the one most related to what I’m experiencing.

So @billdoepp, I had the problem with not being able to install rstan from source too, but managed to solve it a bit serendipitously. The issue seems to be with R Open rprofile.site file, which lies in the “etc” folder of its install directory. Can’t see exactly why but it seems the way it writes its branding message can have unintended effects. If you remove the following lines, being careful with respecting the closure brackets before and after them, rstan installation from source should work… Or at least it did for me!

else if (!quiet) {
	cat("Microsoft R Open ",R.version$major,".",R.version$minor,"\n",sep="")
    cat("The enhanced R distribution from Microsoft\n",sep="")
    cat("Microsoft packages Copyright (C)", Revo.version$year, "Microsoft Corporation\n\n")
	if (MKLmsg == "") {
	   cat(paste("Using the Intel MKL for parallel mathematical computing (using", ncores, "cores).\n", sep = " "))
	} else {
	   cat(MKLmsg)
	}
	cat("\nDefault CRAN mirror snapshot taken on ",repos.date, ".", sep = "")
	cat("\n", "See: https://mran.microsoft.com/.",sep="")
	cat("\n\n")
}	

Now, even after installing rstan and RStanHeaders from source I cannot run the rstan example. This is the output and errors I get: https://pastebin.com/j3PgL88Q

And my diagnostics:

> Sys.getenv("PATH") [1] "C:\\Research\\RTools\\usr\\bin;C:\\Windows\\System32\\wbem;C:\\Windows\\System32\\wbem;C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.0\\bin;C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.0\\libnvvp;C:\\Windows\\System32\\wbem;C:\\ProgramData\\Oracle\\Java\\javapath_target_3265750;C:\\Windows\\System32;C:\\Windows;C:\\Windows\\System32\\wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0;C:\\Program Files (x86)\\Bitvise SSH Client;C:\\Program Files\\Calibre2;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Program Files\\Git\\cmd;C:\\Users\\Antonio\\AppData\\Local\\Microsoft\\WindowsApps;C:\\adb;C:\\ProgramData\\chocolatey\\bin;C:\\Windows\\System32;C:\\Windows;C:\\Windows\\System32\\wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0;C:\\Windows\\System32\\OpenSSH;C:\\Program Files\\Docker Toolbox;C:\\libxml2\\bin;C:\\libxml2\\include;C:\\libxml2\\lib;C:\\Program Files\\MiKTeX\\miktex\\bin\\x64;C:\\Program Files\\NVIDIA Corporation\\NVIDIA NvDLISR;C:\\Program Files\\TortoiseSVN\\bin;C:\\Users\\Antonio\\AppData\\Local\\GitHubDesktop\\bin;C:\\Users\\Antonio\\AppData\\Local\\Pandoc;C:\\Program Files (x86)\\GnuPG\\bin;C:\\Windows\\System32;C:\\Windows;C:\\Windows\\System32\\wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0;C:\\Windows\\System32\\OpenSSH"

> Sys.getenv("BINPREF") [1] ""

> readLines("~/.Renviron") [1] "PATH=\"${RTOOLS40_HOME}\\usr\\bin;${PATH}\""

Also I have already deleted my .Rprofile and .Renviron files following advice on other threads. Thank you in advance for any help as I don’t know what else to try!

sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)
Matrix products: default
locale:
[1] LC_COLLATE=Spanish_Spain.1252 LC_CTYPE=Spanish_Spain.1252
[3] LC_MONETARY=Spanish_Spain.1252 LC_NUMERIC=C
[5] LC_TIME=Spanish_Spain.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] rstan_2.21.2 ggplot2_3.3.2 StanHeaders_2.21.0-6
[4] RevoUtils_11.0.2 RevoUtilsMath_11.0.0
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.3 gtable_0.3.0 pkgconfig_2.0.3 rlang_0.4.7
[13] cli_2.0.2 curl_4.3 parallel_4.0.2 loo_2.3.1
[17] gridExtra_2.3 withr_2.3.0 dplyr_1.0.2 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 purrr_0.3.4 callr_3.4.4 magrittr_1.5
[33] codetools_0.2-16 matrixStats_0.57.0 scales_1.1.1 ps_1.3.4
[37] ellipsis_0.3.1 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