Compilation error

Hello everyone.

I’m trying to set up rstan, for use with brms. Despite following instructions, and reinstalling several times, I can’t even get the example() to run.

I’m on Windows 10
I have Microsoft R Open 4.0.2, in RStudio 2021.09.2 Build 382
RTools 4.0 is working
I installed rstan, StanHeaders, Rcpp, RcppEigen, RcppParallel, BH using install.packages(“package name”, source = TRUE, dependencies = TRUE)

writeLines(readLines(file.path(Sys.getenv(“HOME”), “.R/Makevars”))) results in
Error in file(con, “r”) : cannot open the connection
In addition: Warning message:
In file(con, “r”) :
cannot open file ‘C:/Users/lewis/Documents/.R/Makevars’: No such file or directory

I had created a Makevars.win file in ~/.R as instructed, which is still there, containing a blank new line then
CXX14FLAGS += -mtune=native -O3 -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2

There’s no difference after renaming it to Makevars (no extension)

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 RStudio
    language (EN)
    collate English_United Kingdom.1252
    ctype English_United Kingdom.1252
    tz Australia/Darwin
    date 2022-02-06

  • Packages ----------------------------------------------------------------------------------------
    package * version date lib source
    backports 1.1.10 2020-09-15 [1] CRAN (R 4.0.2)
    BH 1.78.0-0 2021-12-15 [1] CRAN (R 4.0.2)
    callr 3.6.0 2021-03-28 [1] CRAN (R 4.0.4)
    checkmate 2.0.0 2020-02-06 [1] CRAN (R 4.0.2)
    cli 2.4.0 2021-04-05 [1] CRAN (R 4.0.5)
    colorspace 1.4-1 2019-03-18 [1] CRAN (R 4.0.2)
    crayon 1.4.1 2021-02-08 [1] CRAN (R 4.0.5)
    desc 1.3.0 2021-03-05 [1] CRAN (R 4.0.5)
    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)
    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.3 2020-12-30 [1] CRAN (R 4.0.5)
    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.17 2020-12-01 [1] CRAN (R 4.0.5)
    isoband 0.2.4 2021-03-03 [1] CRAN (R 4.0.5)
    labeling 0.4.2 2020-10-20 [1] CRAN (R 4.0.3)
    lattice 0.20-41 2020-04-02 [2] CRAN (R 4.0.2)
    lifecycle 1.0.0 2021-02-15 [1] CRAN (R 4.0.5)
    loo 2.4.1 2020-12-09 [1] CRAN (R 4.0.5)
    magrittr 2.0.1 2020-11-17 [1] CRAN (R 4.0.5)
    MASS 7.3-53.1 2021-02-12 [1] CRAN (R 4.0.5)
    Matrix 1.2-18 2019-11-27 [1] CRAN (R 4.0.3)
    matrixStats 0.58.0 2021-01-29 [1] CRAN (R 4.0.5)
    mgcv 1.8-34 2021-02-16 [1] CRAN (R 4.0.5)
    munsell 0.5.0 2018-06-12 [1] CRAN (R 4.0.2)
    nlme 3.1-152 2021-02-04 [1] CRAN (R 4.0.5)
    pillar 1.4.6 2020-07-10 [1] CRAN (R 4.0.2)
    pkgbuild 1.2.0 2020-12-15 [1] CRAN (R 4.0.5)
    pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.0.2)
    prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.0.2)
    processx 3.5.1 2021-04-04 [1] CRAN (R 4.0.5)
    ps 1.6.0 2021-02-28 [1] CRAN (R 4.0.5)
    R6 2.5.0 2020-10-28 [1] CRAN (R 4.0.5)
    RColorBrewer 1.1-2 2014-12-07 [1] CRAN (R 4.0.0)
    Rcpp 1.0.8 2022-01-13 [1] CRAN (R 4.0.5)
    RcppEigen 0.3.3.9.1 2020-12-17 [1] CRAN (R 4.0.5)
    RcppParallel 5.0.2 2020-06-24 [1] CRAN (R 4.0.2)
    rlang 0.4.10 2020-12-30 [1] CRAN (R 4.0.5)
    rprojroot 2.0.2 2020-11-15 [1] CRAN (R 4.0.5)
    rstan * 2.21.3 2021-12-19 [1] CRAN (R 4.0.2)
    scales 1.1.1 2020-05-11 [1] CRAN (R 4.0.2)
    StanHeaders * 2.21.0-7 2020-12-17 [1] CRAN (R 4.0.5)
    tibble 3.0.4 2020-10-12 [1] CRAN (R 4.0.2)
    utf8 1.1.4 2018-05-24 [1] CRAN (R 4.0.2)
    vctrs 0.3.7 2021-03-29 [1] CRAN (R 4.0.5)
    viridisLite 0.4.0 2021-04-13 [1] CRAN (R 4.0.2)
    withr 2.4.1 2021-01-26 [1] CRAN (R 4.0.5)

[1] C:/Users/lewis/Documents/R/win-library/4.0
[2] C:/Program Files/Microsoft/R Open/R-4.0.2/library

Compilation ERROR, function(s)/method(s) not created!
Error in compileCode(f, code, language = language, verbose = verbose) : 
  C:/rtools40/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: file890d2891.o:file890d2891.cpp:(.text$_ZN3tbb8internal26task_scheduler_observer_v3D0Ev[_ZN3tbb8internal26task_scheduler_observer_v3D0Ev]+0x1c): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:/rtools40/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: file890d2891.o:file890d2891.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD0Ev[_ZN3tbb10interface623task_scheduler_observerD0Ev]+0x1c): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:/rtools40/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: file890d2891.o:file890d2891.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD0Ev[_ZN3tbb10interface623task_scheduler_observerD0Ev]+0x37): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:/

traceback() gives:
13: stop(tail(errmsg))
12: compileCode(f, code, language = language, verbose = verbose)
11: cxxfunction(sig = sig, body = body, plugin = plugin, includes = includes,
settings = settings, …, verbose = verbose)
10: force(code)
9: withr::with_path(rtools_path(), code)
8: pkgbuild::with_build_tools(cxxfunction(sig = sig, body = body,
plugin = plugin, includes = includes, settings = settings,
…, verbose = verbose), required = rstan_options(“required”) &&
!identical(Sys.getenv(“WINDOWS”), “TRUE”) && !identical(Sys.getenv(“R_PACKAGE_SOURCE”),
“”))
7: cxxfunctionplus(signature(), body = paste(" return Rcpp::wrap("",
model_name, “");”, sep = “”), includes = inc, plugin = “rstan”,
save_dso = save_dso | auto_write, module_name = paste(“stan_fit4”,
model_cppname, “_mod”, sep = “”), verbose = verbose)
6: stan_model(model_code = stancode, verbose = TRUE) at Rex8903be3557f#9
5: eval(ei, envir)
4: eval(ei, envir)
3: withVisible(eval(ei, envir))
2: source(tf, local, echo = echo, prompt.echo = paste0(prompt.prefix,
getOption(“prompt”)), continue.echo = paste0(prompt.prefix,
getOption(“continue”)), verbose = verbose, max.deparse.length = Inf,
encoding = “UTF-8”, skip.echo = skips, keep.source = TRUE)
1: example(stan_model, package = “rstan”, run.dontrun = TRUE)

I’m stumped.

The error here is not with your Makevars. Unfortunately R Open has some compatibility issues with the current rstan.

If you’re aiming to use brms, I’d recommend installing cmdstanr: Getting started with CmdStanR • cmdstanr

and using the brms option backend="cmdstanr"

Thanks, much more promising:

All 4 chains finished successfully.
Mean chain execution time: 5.9 seconds.
Total execution time: 24.4 seconds.

Just one error that’s hard to resolve:

Error in loadNamespace(name) : there is no package called ‘posterior’

Difficult to install posterior for some reason:
Error: object ‘format_glimpse’ is not exported by ‘namespace:pillar’
Execution halted
ERROR: lazy loading failed for package ‘posterior’

  • removing ‘C:/Users/lewis/Documents/R/win-library/4.0/posterior’
    Warning in install.packages :
    installation of package ‘C:/Users/lewis/Desktop/posterior_1.2.0.tar.gz’ had non-zero exit status

Am I going about the lack of posterior wrong?

Try reinstalling the pillar package and then installing the posterior package again, that might fix it

Aaaahhh. That’s better. Success. Thanks very much, the first brms vignette is working.

1 Like