Error in compileCode(f, code, language = language, verbose = verbose)

When I run the brms package for analysis, it Compiling Stan program… After the error, I hope I can get your help, thanks.

And here is my sessionINFO():
R version 4.2.1 (2022-06-23 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22000)

Matrix products: default

locale:
[1] LC_COLLATE=Chinese (Simplified)_China.utf8 LC_CTYPE=Chinese (Simplified)_China.utf8 LC_MONETARY=Chinese (Simplified)_China.utf8
[4] LC_NUMERIC=C LC_TIME=Chinese (Simplified)_China.utf8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] rstan_2.21.7 ggplot2_3.3.6 StanHeaders_2.21.0-7 brms_2.18.0 Rcpp_1.0.9 readxl_1.4.1

loaded via a namespace (and not attached):
[1] nlme_3.1-158 matrixStats_0.62.0 xts_0.12.1 threejs_0.3.3 tensorA_0.36.2 tools_4.2.1 backports_1.4.1
[8] utf8_1.2.2 R6_2.5.1 DT_0.25 metafor_3.8-1 DBI_1.1.3 colorspace_2.0-3 withr_2.5.0
[15] tidyselect_1.1.2 gridExtra_2.3 prettyunits_1.1.1 processx_3.7.0 Brobdingnag_1.2-7 compiler_4.2.1 cli_3.3.0
[22] shinyjs_2.1.0 colourpicker_1.1.1 posterior_1.3.1 scales_1.2.1 dygraphs_1.1.1.6 checkmate_2.1.0 mvtnorm_1.1-3
[29] ggridges_0.5.4 callr_3.7.1 stringr_1.4.0 digest_0.6.29 base64enc_0.1-3 pkgconfig_2.0.3 htmltools_0.5.3
[36] fastmap_1.1.0 htmlwidgets_1.5.4 rlang_1.0.5 rstudioapi_0.13 shiny_1.7.2 farver_2.1.1 generics_0.1.3
[43] zoo_1.8-10 crosstalk_1.2.0 gtools_3.9.3 dplyr_1.0.10 distributional_0.3.1 inline_0.3.19 magrittr_2.0.3
[50] loo_2.5.1 bayesplot_1.9.0 metadat_1.2-0 Matrix_1.5-1 munsell_0.5.0 fansi_1.0.3 abind_1.4-5
[57] lifecycle_1.0.2 stringi_1.7.8 mathjaxr_1.6-0 pkgbuild_1.3.1 plyr_1.8.7 grid_4.2.1 parallel_4.2.1
[64] promises_1.2.0.1 crayon_1.5.1 miniUI_0.1.1.1 lattice_0.20-45 ps_1.7.1 pillar_1.8.1 igraph_1.3.4
[71] markdown_1.1 shinystan_2.6.0 reshape2_1.4.4 codetools_0.2-18 stats4_4.2.1 rstantools_2.2.0 glue_1.6.2
[78] RcppParallel_5.1.5 vctrs_0.4.1 httpuv_1.6.6 cellranger_1.1.0 gtable_0.3.1 purrr_0.3.4 assertthat_0.2.1
[85] mime_0.12 xtable_1.8-4 coda_0.19-4 later_1.3.0 tibble_3.1.8 shinythemes_1.2.0 ellipsis_0.3.2
[92] bridgesampling_1.1-2

Operating System: Windows 11
Compiler/Toolkit: rstan/rstudio

code:
library(readxl)
library(brms)
dara_choose ← read_excel(“dara_choose.xlsx”)
dara_choose$se<-sqrt(dara_choose$vi)
m_total = brm(data = dara_choose,
yi | se(se) ~ 1 + (1 | study/id))

output:
Compiling Stan program…
make cmd is
make -f “E:/Learning Soft2/R-4.2.1/etc/x64/Makeconf” -f “E:/Learning Soft2/R-4.2.1/share/make/winshlib.mk” -f “C:/Users/aa271/Documents/.R/Makevars.win” CXX=‘(CXX14) (CXX14STD)’ CXXFLAGS=‘(CXX14FLAGS)' CXXPICFLAGS='(CXX14PICFLAGS)’ SHLIB_LDFLAGS=‘(SHLIB_CXX14LDFLAGS)' SHLIB_LD='(SHLIB_CXX14LD)’ SHLIB=“file6914638220d5.dll” WIN=64 TCLBIN= OBJECTS=“file6914638220d5.o”

make would use
if test “zfile6914638220d5.o” != “z”; then
if test -e “file6914638220d5-win.def”; then
echo g++ -shared -s -static-libgcc -o file6914638220d5.dll file6914638220d5-win.def file6914638220d5.o -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib" -L"E:/Learning Soft2/R-4.2.1/bin/x64" -lR ;
g++ -shared -s -static-libgcc -o file6914638220d5.dll file6914638220d5-win.def file6914638220d5.o -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib" -L"E:/Learning Soft2/R-4.2.1/bin/x64" -lR ;
else
echo EXPORTS > tmp.def;
nm file6914638220d5.o | sed -n ‘s/^.* [BCDRT] / /p’ | sed -e ‘/[.]refptr[.]/d’ -e ‘/[.]weak[.]/d’ | sed ‘s/[^ ][^ ]*/“&”/g’ >> tmp.def;
echo g++ -shared -s -static-libgcc -o file6914638220d5.dll tmp.def file6914638220d5.o -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib" -L"E:/Learning Soft2/R-4.2.1/bin/x64" -lR ;
g++ -shared -s -static-libgcc -o file6914638220d5.dll tmp.def file6914638220d5.o -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib" -L"E:/Learning Soft2/R-4.2.1/bin/x64" -lR ;
rm -f tmp.def;
fi
fi
Error in compileCode(f, code, language = language, verbose = verbose) :
C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file6914638220d5.o:file6914638220d5.cpp:(.text$_ZN3tbb8internal26task_scheduler_observer_v3D0Ev[_ZN3tbb8internal26task_scheduler_observer_v3D0Ev]+0x1d): undefined reference to tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file6914638220d5.o:file6914638220d5.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x1d): undefined reference to tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file6914638220d5.o:file6914638220d5.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x3a): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file6914638220d5.o:file6914638220d5.cpp:(.text$_ZN3tbb10interface
Error in sink(type = “output”) : invalid connection

code:example(stan_model, package = “rstan”, run.dontrun = TRUE)

output:
output.txt (35.5 KB)

See the RStan Getting Started Guide

1 Like

Hello, I ran these two pieces of code according to the GUIDE:

install.packages(“StanHeaders”, repos = c(“Repository for distributing (some) stan-dev R packages | r-packages”, getOption(“repos”)))
install.packages(“rstan”, repos = c(“Repository for distributing (some) stan-dev R packages | r-packages”, getOption(“repos”)))

But it didn’t solve the problem, and the error still occurs:

make cmd is
make -f “E:/Learning Soft2/R-4.2.1/etc/x64/Makeconf” -f “E:/Learning Soft2/R-4.2.1/share/make/winshlib.mk” -f “C:/Users/aa271/Documents/.R/Makevars.win” CXX=‘
(
C
X
X
14
)
(CXX14STD)’ CXXFLAGS=‘
(
C
X
X
14
F
L
A
G
S
)

C
X
X
P
I
C
F
L
A
G
S


(CXX14PICFLAGS)’ SHLIB_LDFLAGS=‘
(
S
H
L
I
B
C
X
X
14
L
D
F
L
A
G
S
)

S
H
L
I
B
L
D


(SHLIB_CXX14LD)’ SHLIB=“file2d18202b3e76.dll” WIN=64 TCLBIN= OBJECTS=“file2d18202b3e76.o”

make would use
if test “zfile2d18202b3e76.o” != “z”; then
if test -e “file2d18202b3e76-win.def”; then
echo g++ -shared -s -static-libgcc -o file2d18202b3e76.dll file2d18202b3e76-win.def file2d18202b3e76.o “E:/Learning Soft2/R-4.2.1/library/rstan/lib/x64/libStanServices.a” -L"E:/Learning Soft2/R-4.2.1/library/StanHeaders/libs/x64" -lStanHeaders -L"E:/Learning Soft2/R-4.2.1/library/RcppParallel/lib/x64" -ltbb -LE:/Learning Soft2/R-4.2.1/library/RcppParallel/lib/x64 -ltbb -ltbbmalloc -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib" -L"E:/Learning Soft2/R-4.2.1/bin/x64" -lR ;
g++ -shared -s -static-libgcc -o file2d18202b3e76.dll file2d18202b3e76-win.def file2d18202b3e76.o “E:/Learning Soft2/R-4.2.1/library/rstan/lib/x64/libStanServices.a” -L"E:/Learning Soft2/R-4.2.1/library/StanHeaders/libs/x64" -lStanHeaders -L"E:/Learning Soft2/R-4.2.1/library/RcppParallel/lib/x64" -ltbb -LE:/Learning Soft2/R-4.2.1/library/RcppParallel/lib/x64 -ltbb -ltbbmalloc -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib" -L"E:/Learning Soft2/R-4.2.1/bin/x64" -lR ;
else
echo EXPORTS > tmp.def;
nm file2d18202b3e76.o | sed -n ‘s/^.* [BCDRT] / /p’ | sed -e ‘/[.]refptr[.]/d’ -e ‘/[.]weak[.]/d’ | sed ‘s/[^ ][^ ]*/“&”/g’ >> tmp.def;
echo g++ -shared -s -static-libgcc -o file2d18202b3e76.dll tmp.def file2d18202b3e76.o “E:/Learning Soft2/R-4.2.1/library/rstan/lib/x64/libStanServices.a” -L"E:/Learning Soft2/R-4.2.1/library/StanHeaders/libs/x64" -lStanHeaders -L"E:/Learning Soft2/R-4.2.1/library/RcppParallel/lib/x64" -ltbb -LE:/Learning Soft2/R-4.2.1/library/RcppParallel/lib/x64 -ltbb -ltbbmalloc -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib" -L"E:/Learning Soft2/R-4.2.1/bin/x64" -lR ;
g++ -shared -s -static-libgcc -o file2d18202b3e76.dll tmp.def file2d18202b3e76.o “E:/Learning Soft2/R-4.2.1/library/rstan/lib/x64/libStanServices.a” -L"E:/Learning Soft2/R-4.2.1/library/StanHeaders/libs/x64" -lStanHeaders -L"E:/Learning Soft2/R-4.2.1/library/RcppParallel/lib/x64" -ltbb -LE:/Learning Soft2/R-4.2.1/library/RcppParallel/lib/x64 -ltbb -ltbbmalloc -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib" -L"E:/Learning Soft2/R-4.2.1/bin/x64" -lR ;
rm -f tmp.def;
fi
fi
Error in compileCode(f, code, language = language, verbose = verbose) :
E:/Learning Soft2/R-4.2.1/library/RcppEigen/include/Eigen/src/Core/ProductEvaluators.h:35:90: required from 'Eigen::internal::evaluator<Eigen::Product<Lhs, Rhs, Option> >::evaluator(const XprType&) [with Lhs = Eigen::Product<Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<double, double>, const Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op, const Eigen::Matrix<double, 1, -1> >, const Eigen::Transpose<Eigen::Matrix<double, -1, 1> > >, Eigen::Matrix<double, -1, -1>, 0>; Rhs = Eigen::Matrix<double, -1, 1>; int Options = 0; Eigen::internal::evaluator<Eigen::Product<Lhs, Rhs, Option> >::XprType = Eigen::Product<Eigen::Product<Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<double, double>, const Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op, const Eigen::Matrix<double, 1, -1> >, const Eigen::Transpose<Eigen::Matrix<double, -1, 1> > >, Eigen::Matrix<double, -1, -1>, 0>, Eigen::Matrix<double, -1, 1>, 0>]'E:/Learning Soft2/R-4.
Error in sink(type = “output”) : invalid connection

Can you post the output from the following commands:

devtools::session_info("rstan")
example(stan_model, package ="rstan", run.dontrun=T, verbose=T)

Thanks.
But the problem was solved when I retired the version of R to 4.1.3.It may have something to do with the version of R.
The error is still reported in version 4.2

CODE:
devtools::session_info(“rstan”)
example(stan_model, package =“rstan”, run.dontrun=T, verbose=T)
output.txt (51.9 KB)