# Compilation Error (Please Help!)

**URL:** <https://discourse.mc-stan.org/t/compilation-error-please-help/9095>\
**Category:** General\
**Created:** [June 4, 2019, 2:38pm UTC](https://discourse.mc-stan.org/t/compilation-error-please-help/9095 "2019-06-04T14:38:08Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![shuai114](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@shuai114](https://discourse.mc-stan.org/u/shuai114)\
**Post date:** [June 4, 2019, 2:38pm UTC](https://discourse.mc-stan.org/t/compilation-error-please-help/9095/1 "2019-06-04T14:38:08Z")

</div>

#### Summary:

Cannot compile rstan.

#### Description:

I tried the 8schools example of rstan: [[RStan Getting Started · stan-dev/rstan Wiki · GitHub](https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started)] and ran into problems.

#### Markvars.win File

CXX14=$(BINPREF)g++  
CXX14FLAGS=-O3 -march=native -mtune=native  
CXX11FLAGS=-O3 -march=native -mtune=native

#### Stan File:

// saved as 8schools.stan  
data {  
int\<lower=0\> J; // number of schools  
real y[J]; // estimated treatment effects  
real\<lower=0\> sigma[J]; // standard error of effect estimates  
}  
parameters {  
real mu; // population treatment effect  
real\<lower=0\> tau; // standard deviation in treatment effects  
vector[J] eta; // unscaled deviation from mu by school  
}  
transformed parameters {  
vector[J] theta = mu + tau \* eta; // school treatment effects  
}  
model {  
target += normal\_lpdf(eta | 0, 1); // prior log-density  
target += normal\_lpdf(y | theta, sigma); // log-likelihood  
}

#### Reproducible Steps:

library(rstan)  
options(mc.cores = parallel::detectCores())  
rstan\_options(auto\_write = TRUE)  
schools\_dat ← list(J = 8,  
y = c(28, 8, -3, 7, -1, 1, 18, 12),  
sigma = c(15, 10, 16, 11, 9, 11, 10, 18))  
fit ← stan(file = ‘8schools.stan’, data = schools\_dat)

#### Current Output:

Error in compileCode(f, code, language = language, verbose = verbose) :  
Compilation ERROR, function(s)/method(s) not created! In file included from C:/Users/swang/R/win-library/3.6/BH/include/boost/random/detail/integer\_log2.hpp:19:0,  
from C:/Users/swang/R/win-library/3.6/BH/include/boost/random/detail/int\_float\_pair.hpp:26,  
from C:/Users/swang/R/win-library/3.6/BH/include/boost/random/exponential\_distribution.hpp:27,  
from C:/Users/swang/R/win-library/3.6/BH/include/boost/random/gamma\_distribution.hpp:25,  
from C:/Users/swang/R/win-library/3.6/StanHeaders/include/stan/math/prim/mat/prob/dirichlet\_rng.hpp:5,  
from C:/Users/swang/R/win-library/3.6/StanHeaders/include/stan/math/prim/mat.hpp:276,  
from C:/Users/swang/R/win-library/3.6/StanHeaders/include/stan/math/rev/mat.hpp:12,  
from C:/Users/swang/R/win-library/3.6/StanHeaders/include/stan/math.hpp:4,  
from C:/Users/swang/R/win-library/3.6/StanHeaders/include/src/stan/  
In addition: Warning message:  
In system(cmd, intern = !verbose) :  
running command ‘C:/PROGRA~1/R/R-36~1.0/bin/x64/R CMD SHLIB file4a3473ca4c69.cpp 2\> file4a3473ca4c69.cpp.err.txt’ had status 1  
Error in sink(type = “output”) : invalid connection

#### Expected Output:

If applicable, the output you expected from RStan.

#### Environment:

> sessionInfo()  
> R version 3.6.0 (2019-04-26)  
> Platform: x86\_64-w64-mingw32/x64 (64-bit)  
> Running under: Windows 10 x64 (build 17134)

Matrix products: default

locale:  
[1] LC\_COLLATE=English\_United States.1252 LC\_CTYPE=English\_United States.1252 LC\_MONETARY=English\_United States.1252  
[4] LC\_NUMERIC=C LC\_TIME=English\_United States.1252

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

other attached packages:  
[1] rstan\_2.18.2 StanHeaders\_2.18.1 ggplot2\_3.1.1

loaded via a namespace (and not attached):  
[1] Rcpp\_1.0.1 pillar\_1.4.1 compiler\_3.6.0 plyr\_1.8.4 prettyunits\_1.0.2 tools\_3.6.0 pkgbuild\_1.0.3  
[8] tibble\_2.1.2 gtable\_0.3.0 pkgconfig\_2.0.2 rlang\_0.3.4 cli\_1.1.0 rstudioapi\_0.10 parallel\_3.6.0  
[15] loo\_2.1.0 gridExtra\_2.3 withr\_2.1.2 dplyr\_0.8.1 stats4\_3.6.0 grid\_3.6.0 tidyselect\_0.2.5  
[22] glue\_1.3.1 inline\_0.3.15 R6\_2.4.0 processx\_3.3.1 callr\_3.2.0 purrr\_0.3.2 magrittr\_1.5  
[29] scales\_1.0.0 ps\_1.3.0 matrixStats\_0.54.0 assertthat\_0.2.1 colorspace\_1.4-1 lazyeval\_0.2.2 munsell\_0.5.0  
[36] crayon\_1.3.4

#### Checking the C++ Toolchain

> pkgbuild::has\_build\_tools(debug = TRUE)  
> [1] TRUE

#### Try the test from the wiki

fx ← inline::cxxfunction( signature(x = “integer”, y = “numeric” ) , ’  
return ScalarReal( INTEGER(x)[0] \* REAL(y)[0] ) ;’ )

make: \*\*\* [C:/PROGRA~1/R/R-36~1.0/share/make/winshlib.mk:13: file4a3425103b7b.dll] Error 127

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

Program source:  
1:  
2: // includes from the plugin  
3: #include \<R.h\>  
4: #include \<Rdefines.h\>  
5: #include \<R\_ext/Error.h\>  
6:  
7:  
8: // user includes  
9:  
10:  
11: // declarations  
12: extern “C” {  
13: SEXP file4a3425103b7b( SEXP x, SEXP y) ;  
14: }  
15:  
16: // definition  
17:  
18: SEXP file4a3425103b7b( SEXP x, SEXP y ){  
19:  
20: return ScalarReal( INTEGER(x)[0] \* REAL(y)[0] ) ;  
21: Rf\_warning(“your C++ program does not return anything”);  
22: return R\_NilValue ;  
23: }  
24:  
25:  
Error in compileCode(f, code, language = language, verbose = verbose) :  
Compilation ERROR, function(s)/method(s) not created! make: \*\*\* [C:/PROGRA~1/R/R-36~1.0/share/make/winshlib.mk:13: file4a3425103b7b.dll] Error 127  
In addition: Warning message:  
In system(cmd, intern = !verbose) :  
running command ‘C:/PROGRA~1/R/R-36~1.0/bin/x64/R CMD SHLIB file4a3425103b7b.cpp 2\> file4a3425103b7b.cpp.err.txt’ had status 1

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [June 4, 2019, 3:36pm UTC](https://discourse.mc-stan.org/t/compilation-error-please-help/9095/2 "2019-06-04T15:36:41Z")

</div>

> [@shuai114](#):
>
> make: \*\*\* [C:/PROGRA~1/R/R-36~1.0/share/make/winshlib.mk:13: file4a3425103b7b.dll] Error 127

It could not find `make`. What does `Sys.getenv('BINPREF')` return?

---

<div class="post-metadata">

**Author:** ![shuai114](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@shuai114](https://discourse.mc-stan.org/u/shuai114)\
**Post date:** [June 6, 2019, 2:10pm UTC](https://discourse.mc-stan.org/t/compilation-error-please-help/9095/3 "2019-06-06T14:10:41Z")

</div>

It is an empty string. Then I create a .Rprofile file with only one line in it as in the following:

Sys.setenv(BINPREF = “C:/Rtools/mingw\_$(WIN)/bin/”)

Now `Sys.getenv('BINPREF')` returns the exact string I write: `"C:/Rtools/mingw_$(WIN)/bin/"`. How can I let R to translate $(WIN)?

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [June 6, 2019, 2:22pm UTC](https://discourse.mc-stan.org/t/compilation-error-please-help/9095/4 "2019-06-06T14:22:54Z")

</div>

R should do that automatically but it is empty except on Windows.

---

<div class="post-metadata">

**Author:** ![shuai114](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@shuai114](https://discourse.mc-stan.org/u/shuai114)\
**Post date:** [June 6, 2019, 2:32pm UTC](https://discourse.mc-stan.org/t/compilation-error-please-help/9095/5 "2019-06-06T14:32:20Z")

</div>

After this fix, now when I run `fit <- stan(file = ‘8schools.stan’, data = schools_dat)`. RStudio asks me to install additional build tools. After clicking yes, RStudio goes ahead to download and install Rtools again. Why does it happen? I have already get it installed. Furthermore, after the reinstallation of Rtools, RStudio asks me to install Rtools another time. How to solve this problem?

---

<div class="post-metadata">

**Author:** ![shuai114](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@shuai114](https://discourse.mc-stan.org/u/shuai114)\
**Post date:** [June 6, 2019, 2:38pm UTC](https://discourse.mc-stan.org/t/compilation-error-please-help/9095/6 "2019-06-06T14:38:18Z")

</div>

After this fix, the same error still exists. How to solve it?

> fx ← inline::cxxfunction( signature(x = “integer”, y = “numeric” ) , ’

- 

```
                       return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ;' )

```

make: \*\*\* [C:/PROGRA~1/R/R-36~1.0/share/make/winshlib.mk:13: file552c5d1d4c4f.dll] Error 127

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

Program source:  
1:  
2: // includes from the plugin  
3: #include \<R.h\>  
4: #include \<Rdefines.h\>  
5: #include \<R\_ext/Error.h\>  
6:  
7:  
8: // user includes  
9:  
10:  
11: // declarations  
12: extern “C” {  
13: SEXP file552c5d1d4c4f( SEXP x, SEXP y) ;  
14: }  
15:  
16: // definition  
17:  
18: SEXP file552c5d1d4c4f( SEXP x, SEXP y ){  
19:  
20: return ScalarReal( INTEGER(x)[0] \* REAL(y)[0] ) ;  
21: Rf\_warning(“your C++ program does not return anything”);  
22: return R\_NilValue ;  
23: }  
24:  
25:  
Error in compileCode(f, code, language = language, verbose = verbose) :  
Compilation ERROR, function(s)/method(s) not created! make: \*\*\* [C:/PROGRA~1/R/R-36~1.0/share/make/winshlib.mk:13: file552c5d1d4c4f.dll] Error 127  
In addition: Warning message:  
In system(cmd, intern = !verbose) :  
running command ‘C:/PROGRA~1/R/R-36~1.0/bin/x64/R CMD SHLIB file552c5d1d4c4f.cpp 2\> file552c5d1d4c4f.cpp.err.txt’ had status 1

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [June 6, 2019, 2:58pm UTC](https://discourse.mc-stan.org/t/compilation-error-please-help/9095/7 "2019-06-06T14:58:59Z")

</div>

You can try first doing

```
options(buildtools.check = NULL)

```

---

<div class="post-metadata">

**Author:** ![shuai114](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@shuai114](https://discourse.mc-stan.org/u/shuai114)\
**Post date:** [June 6, 2019, 7:40pm UTC](https://discourse.mc-stan.org/t/compilation-error-please-help/9095/8 "2019-06-06T19:40:50Z")

</div>

Now I get the following error message:

> fit ← stan(file = ‘8schools.stan’, data = schools\_dat)

Error in compileCode(f, code, language = language, verbose = verbose) :  
Compilation ERROR, function(s)/method(s) not created! In file included from C:/Users/swang/R/win-library/3.6/BH/include/boost/random/detail/integer\_log2.hpp:19:0,  
from C:/Users/swang/R/win-library/3.6/BH/include/boost/random/detail/int\_float\_pair.hpp:26,  
from C:/Users/swang/R/win-library/3.6/BH/include/boost/random/exponential\_distribution.hpp:27,  
from C:/Users/swang/R/win-library/3.6/BH/include/boost/random/gamma\_distribution.hpp:25,  
from C:/Users/swang/R/win-library/3.6/StanHeaders/include/stan/math/prim/mat/prob/dirichlet\_rng.hpp:5,  
from C:/Users/swang/R/win-library/3.6/StanHeaders/include/stan/math/prim/mat.hpp:276,  
from C:/Users/swang/R/win-library/3.6/StanHeaders/include/stan/math/rev/mat.hpp:12,  
from C:/Users/swang/R/win-library/3.6/StanHeaders/include/stan/math.hpp:4,  
from C:/Users/swang/R/win-library/3.6/StanHeaders/include/src/stan/  
In addition: Warning message:  
In system(cmd, intern = !verbose) :  
running command ‘C:/PROGRA~1/R/R-36~1.0/bin/x64/R CMD SHLIB file61cc246763b7.cpp 2\> file61cc246763b7.cpp.err.txt’ had status 1  
Error in sink(type = “output”) : invalid connection

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [June 6, 2019, 7:47pm UTC](https://discourse.mc-stan.org/t/compilation-error-please-help/9095/9 "2019-06-06T19:47:18Z")

</div>

We need that call with the `verbose = TRUE` argument to see the underlying error message.

---

<div class="post-metadata">

**Author:** ![jmh530](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jmh530/32/4579_2.png) [@jmh530](https://discourse.mc-stan.org/u/jmh530)\
**Post date:** [August 1, 2019, 7:38pm UTC](https://discourse.mc-stan.org/t/compilation-error-please-help/9095/10 "2019-08-01T19:38:59Z")

</div>

@bgoodri I am getting this error too and the fix others have suggested does not help. I ran it with verbose=TRUE and this is the last part of the compilation that I saw (the rest is stuff from the program source).

Compilation argument:  
C:/PROGRA~1/R/R-36~1.1/bin/x64/R CMD SHLIB filea81c61942c20.cpp 2\> filea81c61942c20.cpp.err.txt  
C:/Rtools/mingw\_64/bin/g++ -std=gnu++11 -I"C:/PROGRA~1/R/R-36~1.1/include" -DNDEBUG -I"C:/Users/jhall/Documents/R/win-library/3.6/Rcpp/include/" -I"C:/Users/jhall/Documents/R/win-library/3.6/RcppEigen/include/" -I"C:/Users/jhall/Documents/R/win-library/3.6/RcppEigen/include/unsupported" -I"C:/Users/jhall/Documents/R/win-library/3.6/BH/include" -I"C:/Users/jhall/Documents/R/win-library/3.6/StanHeaders/include/src/" -I"C:/Users/jhall/Documents/R/win-library/3.6/StanHeaders/include/" -I"C:/Users/jhall/Documents/R/win-library/3.6/rstan/include" -DEIGEN\_NO\_DEBUG -DBOOST\_DISABLE\_ASSERTS -std=c++1y -march=core2 -O3 -march=native -mtune=native -c filea81c61942c20.cpp -o filea81c61942c20.o  
In file included from C:/Users/jhall/Documents/R/win-library/3.6/BH/include/boost/random/detail/integer\_log2.hpp:19:0,  
from C:/Users/jhall/Documents/R/win-library/3.6/BH/include/boost/random/detail/int\_float\_pair.hpp:26,  
from C:/Users/jhall/Documents/R/win-library/3.6/BH/include/boost/random/exponential\_distribution.hpp:27,  
from C:/Users/jhall/Documents/R/win-library/3.6/BH/include/boost/random/gamma\_distribution.hpp:25,  
from C:/Users/jhall/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/mat/prob/dirichlet\_rng.hpp:5,  
from C:/Users/jhall/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/mat.hpp:292,  
from C:/Users/jhall/Documents/R/win-library/3.6/StanHeaders/include/stan/math/rev/mat.hpp:12,  
from C:/Users/jhall/Documents/R/win-library/3.6/StanHeaders/include/stan/math.hpp:4,  
from C:/Users/jhall/Documents/R/win-library/3.6/StanHeaders/include/src/stan/model/model\_header.hpp:4,  
from filea81c61942c20.cpp:8:  
C:/Users/jhall/Documents/R/win-library/3.6/BH/include/boost/pending/integer\_log2.hpp:7:89: note: #pragma message: This header is deprecated. Use \<boost/integer/integer\_log2.hpp\> instead.  
BOOST\_HEADER\_DEPRECATED("\<boost/integer/integer\_log2.hpp\>");  
^

cc1plus.exe: out of memory allocating 65536 bytes  
make: \*\*\* [C:/PROGRA~1/R/R-36~1.1/etc/x64/Makeconf:215: filea81c61942c20.o] Error 1

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

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [August 1, 2019, 10:45pm UTC](https://discourse.mc-stan.org/t/compilation-error-please-help/9095/11 "2019-08-01T22:45:39Z")

</div>

> [@jmh530](#):
>
> cc1plus.exe: out of memory allocating 65536 bytes

You ran out of RAM.

---

<div class="post-metadata">

**Author:** ![jmh530](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jmh530/32/4579_2.png) [@jmh530](https://discourse.mc-stan.org/u/jmh530)\
**Post date:** [August 2, 2019, 6:08pm UTC](https://discourse.mc-stan.org/t/compilation-error-please-help/9095/12 "2019-08-02T18:08:06Z")

</div>

Ah, thanks. I closed some other applications and that helped. It’s kind of crazy though, on just the 8schools example I saw that it was using 2gb of RAM in the Windows Task Manager at one point (leaving on the optimizations and using the previous version of stan).

The error about being out of memory wasn’t the only one I received while playing around with this. One thing that I noticed is that when there is an error, it prints out all that source code for some reason. I don’t really know what that happens, and I imagine in some cases there is a use for it. Regardless, it can print out so much that Rstudio is cutting off what was above it. So I can’t see what happened before that. If there were a way to optionally prevent the source code from being printed, then it might be a little easier to follow.

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [August 4, 2019, 12:07am UTC](https://discourse.mc-stan.org/t/compilation-error-please-help/9095/13 "2019-08-04T00:07:31Z")

</div>

The dump of the source code comes from the **inline** package, so there’s not much we can do about it if we also want to see what the compiler error is.
