Compilation error Windows 10

Hello,

I have this compilation issue in Windows 10. Any ideas or suggestions on how to solve it? Thanks.

Compiling Stan program...
make cmd is
  make -f "C:/Users/Y75149~1/MINICO~1/lib/R/etc/x64/Makeconf" -f "C:/Users/Y75149~1/MINICO~1/lib/R/share/make/winshlib.mk" CXX='$(CXX14) $(CXX14STD)' CXXFLAGS='$(CXX14FLAGS)' CXXPICFLAGS='$(CXX14PICFLAGS)' SHLIB_LDFLAGS='$(SHLIB_CXX14LDFLAGS)' SHLIB_LD='$(SHLIB_CXX14LD)' SHLIB="file19e418ec322a.dll" WIN=64 TCLBIN=64 OBJECTS="file19e418ec322a.o"

make would use
if test "zfile19e418ec322a.o" != "z"; then \
  if test -e "file19e418ec322a-win.def"; then \
    echo g++  -shared -s  -o file19e418ec322a.dll file19e418ec322a-win.def file19e418ec322a.o   "C:/Users/Y7514957C/Miniconda3/Lib/R/library/rstan/lib/x64/libStanServices.a" -L"C:/Users/Y7514957C/Miniconda3/Lib/R/library/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/Y7514957C/Miniconda3/Lib/R/library/RcppParallel/lib/x64" -ltbb  -L"C:/Users/Y75149~1/MINICO~1/lib/R/bin/x64" -lR ; \
    g++  -shared -s  -o file19e418ec322a.dll file19e418ec322a-win.def file19e418ec322a.o   "C:/Users/Y7514957C/Miniconda3/Lib/R/library/rstan/lib/x64/libStanServices.a" -L"C:/Users/Y7514957C/Miniconda3/Lib/R/library/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/Y7514957C/Miniconda3/Lib/R/library/RcppParallel/lib/x64" -ltbb  -L"C:/Users/Y75149~1/MINICO~1/lib/R/bin/x64" -lR ; \
  else \
    echo EXPORTS > tmp.def; \
    nm file19e418ec322a.o | sed -n 's/^.* [BCDRT] / /p' | sed -e '/[.]refptr[.]/d' -e '/[.]weak[.]/d' | sed 's/[^ ][^ ]*/"&"/g'  >> tmp.def; \
    echo g++  -shared -s  -o file19e418ec322a.dll tmp.def file19e418ec322a.o   "C:/Users/Y7514957C/Miniconda3/Lib/R/library/rstan/lib/x64/libStanServices.a" -L"C:/Users/Y7514957C/Miniconda3/Lib/R/library/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/Y7514957C/Miniconda3/Lib/R/library/RcppParallel/lib/x64" -ltbb  -L"C:/Users/Y75149~1/MINICO~1/lib/R/bin/x64" -lR ; \
    g++  -shared -s  -o file19e418ec322a.dll tmp.def file19e418ec322a.o   "C:/Users/Y7514957C/Miniconda3/Lib/R/library/rstan/lib/x64/libStanServices.a" -L"C:/Users/Y7514957C/Miniconda3/Lib/R/library/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/Y7514957C/Miniconda3/Lib/R/library/RcppParallel/lib/x64" -ltbb  -L"C:/Users/Y75149~1/MINICO~1/lib/R/bin/x64" -lR ; \
    rm -f tmp.def; \
  fi \
fi

Info about R on my machine:

> devtools::session_info("rstan")
- Session info ---------------------------------------------------------------
 setting  value
 version  R version 4.0.2 (2020-06-22)
 os       Windows 10 x64
 system   x86_64, mingw32
 ui       RTerm
 language (EN)
 collate  Spanish_Spain.1252
 ctype    Spanish_Spain.1252
 tz       Europe/Paris
 date     2020-09-14

- Packages -------------------------------------------------------------------
 ! package      * version   date       lib source
   assertthat     0.2.1     2019-03-21 [1] CRAN (R 4.0.2)
   backports      1.1.9     2020-08-24 [1] CRAN (R 4.0.2)
   BH             1.72.0-3  2020-01-08 [1] CRAN (R 4.0.0)
   callr          3.4.4     2020-09-07 [1] CRAN (R 4.0.2)
   checkmate      2.0.0     2020-02-06 [1] CRAN (R 4.0.2)
   cli            2.0.2     2020-02-28 [1] CRAN (R 4.0.2)
   colorspace     1.4-1     2019-03-18 [1] CRAN (R 4.0.2)
   crayon         1.3.4     2017-09-16 [1] CRAN (R 4.0.2)
   curl           4.3       2019-12-02 [1] CRAN (R 4.0.2)
   desc           1.2.0     2018-05-01 [1] CRAN (R 4.0.2)
   digest         0.6.25    2020-02-23 [1] CRAN (R 4.0.2)
   ellipsis       0.3.1     2020-05-15 [1] CRAN (R 4.0.2)
   evaluate       0.14      2019-05-28 [1] CRAN (R 4.0.2)
   fansi          0.4.1     2020-01-08 [1] CRAN (R 4.0.2)
   farver         2.0.3     2020-01-16 [1] CRAN (R 4.0.2)
   ggplot2      * 3.3.2     2020-06-19 [1] CRAN (R 4.0.2)
   glue           1.4.2     2020-08-27 [1] CRAN (R 4.0.2)
   gridExtra      2.3       2017-09-09 [1] CRAN (R 4.0.2)
   gtable         0.3.0     2019-03-25 [1] CRAN (R 4.0.2)
   inline         0.3.16    2020-09-06 [1] CRAN (R 4.0.2)
   isoband        0.2.2     2020-06-20 [1] CRAN (R 4.0.2)
   jsonlite       1.7.1     2020-09-07 [1] CRAN (R 4.0.2)
   labeling       0.3       2014-08-23 [1] CRAN (R 4.0.0)
   lattice        0.20-41   2020-04-02 [1] CRAN (R 4.0.2)
   lifecycle      0.2.0     2020-03-06 [1] CRAN (R 4.0.2)
   loo            2.3.1     2020-07-14 [1] CRAN (R 4.0.2)
   magrittr       1.5       2014-11-22 [1] CRAN (R 4.0.2)
   MASS           7.3-53    2020-09-09 [1] CRAN (R 4.0.2)
   Matrix         1.2-18    2019-11-27 [1] CRAN (R 4.0.2)
   matrixStats    0.56.0    2020-03-13 [1] CRAN (R 4.0.2)
   mgcv           1.8-33    2020-08-27 [1] CRAN (R 4.0.2)
   munsell        0.5.0     2018-06-12 [1] CRAN (R 4.0.2)
   nlme           3.1-149   2020-08-23 [1] CRAN (R 4.0.2)
   pillar         1.4.6     2020-07-10 [1] CRAN (R 4.0.2)
   pkgbuild       1.1.0     2020-07-13 [1] CRAN (R 4.0.2)
   pkgconfig      2.0.3     2019-09-22 [1] CRAN (R 4.0.2)
   pkgload        1.1.0     2020-05-29 [1] CRAN (R 4.0.2)
   praise         1.0.0     2015-08-11 [1] CRAN (R 4.0.2)
   prettyunits    1.1.1     2020-01-24 [1] CRAN (R 4.0.2)
   processx       3.4.4     2020-09-03 [1] CRAN (R 4.0.2)
   ps             1.3.4     2020-08-11 [1] CRAN (R 4.0.2)
   R6             2.4.1     2019-11-12 [1] CRAN (R 4.0.2)
   RColorBrewer   1.1-2     2014-12-07 [1] CRAN (R 4.0.0)
   Rcpp         * 1.0.5     2020-07-06 [1] CRAN (R 4.0.2)
   RcppEigen      0.3.3.7.0 2019-11-16 [1] CRAN (R 4.0.2)
 D RcppParallel   5.0.2     2020-06-24 [1] CRAN (R 4.0.2)
   rlang          0.4.7     2020-07-09 [1] CRAN (R 4.0.2)
   rprojroot      1.3-2     2018-01-03 [1] CRAN (R 4.0.2)
   rstan        * 2.21.2    2020-07-27 [1] CRAN (R 4.0.2)
   rstudioapi     0.11      2020-02-07 [1] CRAN (R 4.0.2)
   scales         1.1.1     2020-05-11 [1] CRAN (R 4.0.2)
   StanHeaders  * 2.21.0-6  2020-08-16 [1] CRAN (R 4.0.2)
   testthat       2.3.2     2020-03-02 [1] CRAN (R 4.0.2)
   tibble         3.0.3     2020-07-10 [1] CRAN (R 4.0.2)
   utf8           1.1.4     2018-05-24 [1] CRAN (R 4.0.2)
   V8             3.2.0     2020-06-19 [1] CRAN (R 4.0.2)
   vctrs          0.3.4     2020-08-29 [1] CRAN (R 4.0.2)
   viridisLite    0.3.0     2018-02-01 [1] CRAN (R 4.0.2)
   withr          2.2.0     2020-04-20 [1] CRAN (R 4.0.2)

Hi Sebastion,

Can you post the outputs from:

Sys.getenv("PATH")
Sys.getenv("BINPREF")
readLines("~/.R/Makevars.win")
readLines("~/.Rprofile")
readLines("~/.Renviron")

Thanks, @andrjohns. This is what I get:

    > Sys.getenv("BINPREF")
[1] ""
> readLines("~/.R/Makevars.win")
Error in file(con, "r") : no se puede abrir la conexión
Además: Warning message:
In file(con, "r") :
  no fue posible abrir el archivo 'C:\Users\Y7514957C\Documents/.R/Makevars.win': No such file or directory
> readLines("~/.Rprofile")
Error in file(con, "r") : no se puede abrir la conexión
Además: Warning message:
In file(con, "r") :
  no fue posible abrir el archivo 'C:\Users\Y7514957C\Documents/.Rprofile': No such file or directory
> readLines("~/.Renviron")
[1] "PATH=\"${RTOOLS40_HOME}\\usr\\bin;${PATH}\""

Where no fue posible abrir el archivo means the file cannot be opened.

Thanks! What do you get from:

Sys.getenv("PATH")
Sys.which("make")

?

Can you also run the rstan example model:

library(rstan)
example(stan_model,run.dontrun=TRUE,verbose=TRUE)

And post any lines that start with error:?

I am getting:

> Sys.getenv("PATH")
[1] "C:\\rtools40\\usr\\bin;C:\\Users\\Y7514957C\\Miniconda3\\Rtools\\bin;C:\\Users\\Y7514957C\\Miniconda3\\Rtools\\mingw_64\\bin;C:\\Users\\Y7514957C\\Miniconda3;C:\\Users\\Y7514957C\\Miniconda3\\Library\\mingw-w64\\bin;C:\\Users\\Y7514957C\\Miniconda3\\Library\\usr\\bin;C:\\Users\\Y7514957C\\Miniconda3\\Library\\bin;C:\\Users\\Y7514957C\\Miniconda3\\Scripts;C:\\Users\\Y7514957C\\Miniconda3\\bin;C:\\Users\\Y7514957C\\Miniconda3\\condabin;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0;C:\\Program Files\\AutoFirma\\AutoFirma;C:\\WINDOWS\\System32\\OpenSSH;C:\\Program Files\\PuTTY;C:\\Users\\Y7514957C\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\Y7514957C\\AppData\\Local\\Programs\\Git\\cmd;C:\\Users\\Y7514957C\\AppData\\Local\\GitHubDesktop\\bin;C:\\Users\\Y7514957C\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Users\\Y7514957C\\AppData\\Local\\Microsoft\\WindowsApps;."
>
> Sys.which("make")
                              make
"C:\\rtools40\\usr\\bin\\make.exe"

When running rstan:

Compilation ERROR, function(s)/method(s) not created!
Error in compileCode(f, code, language = language, verbose = verbose) :
  C:/Users/Y7514957C/Miniconda3/Lib/R/library/rstan/lib/x64/libStanServices.a(stan_fit.o):stan_fit.cpp:(.text$_ZN4stan8services4util20run_adaptive_samplerINS_4mcmc24adapt_dense_e_static_hmcINS_5model10model_baseEN5boost6random23additive_combine_engineINS8_26linear_congruential_engineIjLj40014ELj0ELj2147483563EEENSA_IjLj40692ELj0ELj2147483399EEEEEEES6_SD_EEvRT_RT0_RSt6vectorIdSaIdEEiiiibRT1_RNS_9callbacks9interruptERNSP_6loggerERNSP_6writerESV_[_ZN4stan8services4util20run_adaptive_samplerINS_4mcmc24adapt_dense_e_static_hmcINS_5model10model_baseEN5boost6random23additive_combine_engineINS8_26linear_congruential_engineIjLj40014ELj0ELj2147483563EEENSA_IjLj40692ELj0ELj2147483399EEEEEEES6_SD_EEvRT_RT0_RSt6vectorIdSaIdEEiiiibRT1_RNS_9callbacks9interruptERNSP_6loggerERNSP_6writerESV_]+0x55c): undefined reference to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::~basic_stringstream()'C:/Users/Y7514957C/Miniconda3/Lib/R/library/rstan/lib/x64/libSta
Además: Warning messages:
1: In find.package(package, lib.loc, verbose = verbose) :
  package 'base' found more than once, using the first from
  "C:/Users/Y7514957C/Miniconda3/lib/R/library/base",
  "C:/Users/Y7514957C/Miniconda3/Lib/R/library/base"
2: In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
  'C:/rtools40/usr/mingw_/bin/g++' not found

Well that’s a new one, haven’t seen that error before!

Can you try reinstalling rstan and StanHeaders from source? i.e.:

install.packages(c("StanHeaders","rstan"),type="source")

I get this:

    ==== C stack trace ===============================

        strlen [0x0x7ffa61edd2d0+16]
        Rf_mkChar [0x0x6c7e2e3d+13]
        ZN4Rcpp6Module12classes_infoEv [0x0x6ac076a9+281]
        Z20Module__classes_infoP7SEXPREC [0x0x6abe1b6a+74]
        Rf_NewFrameConfirm [0x0x6c7ae358+33656]
        R_initAssignSymbols [0x0x6c7ff0a2+47234]
        Rf_eval [0x0x6c808056+534]
        R_cmpfun1 [0x0x6c809d17+1255]
        Rf_applyClosure [0x0x6c80af27+439]
        R_initAssignSymbols [0x0x6c800ef3+54995]
        Rf_eval [0x0x6c808056+534]
        Rf_eval [0x0x6c8088f9+2745]
        Rf_eval [0x0x6c808d4c+3852]
        R_initAssignSymbols [0x0x6c7fecbd+46237]
        Rf_eval [0x0x6c808056+534]
        Rf_eval [0x0x6c8088f9+2745]
        Rf_eval [0x0x6c808d4c+3852]
        R_initAssignSymbols [0x0x6c7fecbd+46237]
        Rf_eval [0x0x6c808056+534]
        Rf_eval [0x0x6c8088f9+2745]
        Rf_eval [0x0x6c808d4c+3852]
        R_initAssignSymbols [0x0x6c7fecbd+46237]
        Rf_eval [0x0x6c808056+534]
        Rf_eval [0x0x6c8088f9+2745]
        Rf_eval [0x0x6c808d4c+3852]
        R_initAssignSymbols [0x0x6c7fecbd+46237]
        Rf_eval [0x0x6c808056+534]
        R_cmpfun1 [0x0x6c809d17+1255]
        Rf_applyClosure [0x0x6c80af27+439]
        R_initAssignSymbols [0x0x6c800ef3+54995]
        Rf_eval [0x0x6c808056+534]
        R_cmpfun1 [0x0x6c809d17+1255]
        Rf_applyClosure [0x0x6c80af27+439]
        R_initAssignSymbols [0x0x6c800ef3+54995]
        Rf_eval [0x0x6c808056+534]
        R_cmpfun1 [0x0x6c809d17+1255]
        Rf_applyClosure [0x0x6c80af27+439]
        R_initAssignSymbols [0x0x6c800ef3+54995]
        Rf_eval [0x0x6c808056+534]
        R_cmpfun1 [0x0x6c809d17+1255]
        Rf_applyClosure [0x0x6c80af27+439]
        R_initAssignSymbols [0x0x6c800ef3+54995]
        Rf_eval [0x0x6c808056+534]
        R_cmpfun1 [0x0x6c809d17+1255]
        Rf_applyClosure [0x0x6c80af27+439]
        R_initAssignSymbols [0x0x6c800ef3+54995]
        Rf_eval [0x0x6c808056+534]
        R_cmpfun1 [0x0x6c809d17+1255]
        Rf_applyClosure [0x0x6c80af27+439]
        R_initAssignSymbols [0x0x6c800ef3+54995]
        Rf_eval [0x0x6c808056+534]
        Rf_eval [0x0x6c8088f9+2745]
        Rf_eval [0x0x6c808d4c+3852]
        R_initAssignSymbols [0x0x6c7fecbd+46237]
        Rf_eval [0x0x6c808056+534]
        Rf_eval [0x0x6c8088f9+2745]
        Rf_eval [0x0x6c808d4c+3852]
        R_initAssignSymbols [0x0x6c7fecbd+46237]
        Rf_eval [0x0x6c808056+534]
        Rf_eval [0x0x6c8088f9+2745]
        Rf_eval [0x0x6c808d4c+3852]
        R_initAssignSymbols [0x0x6c7fecbd+46237]
ERROR: loading failed
* removing 'C:/Users/Y7514957C/Miniconda3/Lib/R/library/rstan'
* restoring previous 'C:/Users/Y7514957C/Miniconda3/Lib/R/library/rstan'

During the installation of the packages or running a model?

During installation :(

Are you able to install any packages from source?
try:

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

Yes, jsonlite installs without problem.

Alright, so something’s a little odd with your compiler. What happens when you run:

fx <- inline::cxxfunction( signature(x = "integer", y = "numeric" ) , 'return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ;' )

I get this:

> fx

An object of class “CFunc”
function (x, y)
.Primitive(".Call")(<pointer: 0x0000000063f41430>, x, y)
<environment: 0x00000000129add48>
Slot “code”:
[1] “\n// includes from the plugin\n#include <R.h>\n#include <Rdefines.h>\n#include <R_ext/Error.h>\n\n\n// user includes\n\n\n// declarations\nextern “C” {\nSEXP file3c489914b2f( SEXP x, SEXP y) ;\n}\n\n// definition\n\nSEXP file3c489914b2f( SEXP x, SEXP y ){\nreturn ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ; \nRf_warning(“your C++ program does not return anything”); \n return R_NilValue ; \n}\n\n\n”

What do you get from:

system("touch foo.cpp")
system("R CMD SHLIB foo.cpp")

And:

Sys.which("g++")
> system("touch foo.cpp")
[1] 0
> system("R CMD SHLIB foo.cpp")
g++ -std=gnu++11  -I"C:/Users/Y75149~1/MINICO~1/lib/R/include" -DNDEBUG          -O2 -Wall  -march=x86-64 -mtune=generic -c foo.cpp -o foo.o
g++ -std=gnu++11 -shared -s -o foo.dll tmp.def foo.o -LC:/Users/Y75149~1/MINICO~1/lib/R/bin/x64 -lR
[1] 0
> Sys.which("g++")
                                                          g++
"C:\\Users\\Y75149~1\\MINICO~1\\Rtools\\mingw_64\\bin\\g++.exe"

Ah that would be the issue, its using the old RTools’ compiler.

You need to edit your PATH variable to remove the lines with the old Rtools directory:

C:\\Users\\Y7514957C\\Miniconda3\\Rtools\\bin;
C:\\Users\\Y7514957C\\Miniconda3\\Rtools\\mingw_64\\bin;

Do you know how to do that on Windows or did you need some info?

It would also be a good idea to uninstall the old RTools (if you don’t need it), just in case

Thanks! Could you give me a hint, I am not a Windows user :)

No worries! This guide should have what you need: https://www.architectryan.com/2018/03/17/add-to-the-path-on-windows-10/

Thank you so much!

Happy to help! Once you’ve changed the PATH variable, restart R and try install rstan and StanHeaders from source again, hopefully it should work without issue

1 Like