# Error caused by missing stan header

**URL:** <https://discourse.mc-stan.org/t/error-caused-by-missing-stan-header/17849>\
**Category:** Modeling\
**Tags:** fitting-issues\
**Created:** [September 4, 2020, 6:13am UTC](https://discourse.mc-stan.org/t/error-caused-by-missing-stan-header/17849 "2020-09-04T06:13:07Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ybordag](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ybordag/32/9243_2.png) [@ybordag](https://discourse.mc-stan.org/u/ybordag)\
**Post date:** [September 4, 2020, 6:13am UTC](https://discourse.mc-stan.org/t/error-caused-by-missing-stan-header/17849/1 "2020-09-04T06:13:07Z")

</div>

Hi all! I’m pretty new to Stan, but the error I’m getting doesn’t seem to be related to my model.

When I tried to do a test run of my model, I got this error output:

Error in compileCode(f, code, language = language, verbose = verbose) :  
Compilation ERROR, function(s)/method(s) not created! In file included from C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/mat/prob/dirichlet\_log.hpp:5:0,  
from C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/mat.hpp:278,  
from C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math/rev/mat.hpp:12,  
from C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math.hpp:4,  
from C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/src/stan/model/model\_header.hpp:4,  
from file399019ac55df.cpp:14:  
C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/mat/prob/dirichlet\_lpmf.hpp: In function ‘stan::return\_type\_t\<T1, T2\> stan::math::dirichlet\_lpmf(const T\_prob&, const T\_prior\_size&)’:  
C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/mat/prob/dirichlet\_l  
In addition: Warning messages:  
1: In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :  
‘C:/Rtools/mingw\_/bin/g++’ not found  
2: In system(cmd, intern = !verbose) :  
running command ‘C:/PROGRA~1/R/R-3.6.3/bin/x64/R CMD SHLIB file399019ac55df.cpp 2\> file399019ac55df.cpp.err.txt’ had status 1  
Error in sink(type = “output”) : invalid connection

I’m not really sure what this is referring to. I’ve tried updating all my libraries and I’m currently using R 3.6.3.

---

<div class="post-metadata">

**Author:** ![torkar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/torkar/32/1355_2.png) [@torkar](https://discourse.mc-stan.org/u/torkar)\
**Post date:** [September 4, 2020, 6:29am UTC](https://discourse.mc-stan.org/t/error-caused-by-missing-stan-header/17849/2 "2020-09-04T06:29:20Z")

</div>

Welcome to the community! I don’t have Windows myself but I know someone who I’m sure will be able to help you out @andrjohns

This here seems to definitely be a problem:

> ‘C:/Rtools/mingw\_/bin/g++’ not found?

---

<div class="post-metadata">

**Author:** ![andrjohns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrjohns/32/15297_2.png) [@andrjohns](https://discourse.mc-stan.org/u/andrjohns)\
**Post date:** [September 4, 2020, 9:34am UTC](https://discourse.mc-stan.org/t/error-caused-by-missing-stan-header/17849/3 "2020-09-04T09:34:42Z")

</div>

Thanks @torkar!

ybordag, can you try running:

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

```

And post any lines that start with `error:`?

---

<div class="post-metadata">

**Author:** ![ybordag](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ybordag/32/9243_2.png) [@ybordag](https://discourse.mc-stan.org/u/ybordag)\
**Post date:** [September 4, 2020, 7:08pm UTC](https://discourse.mc-stan.org/t/error-caused-by-missing-stan-header/17849/4 "2020-09-04T19:08:49Z")

</div>

I don’t think I get any error lines, but I do get a few warnings, I still see the following warnings though:

Warning messages:  
1: In find.package(package, lib.loc, verbose = verbose) :  
package ‘base’ found more than once, using the first from  
“C:/PROGRA~1/R/R-3.6.3/library/base”,  
“C:/Program Files/R/R-3.6.3/library/base”  
2: In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :  
‘C:/Rtools/mingw\_/bin/g++’ not found

and the sampling apparently ran successfully.

This part of the log seems to be related to the issue I had before:

Compilation argument:  
C:/PROGRA~1/R/R-3.6.3/bin/x64/R CMD SHLIB filef241dfcb3f.cpp 2\> filef241dfcb3f.cpp.err.txt  
c:/Rtools/mingw\_64/bin/g++ -std=gnu++11 -I"C:/PROGRA~1/R/R-3.6.3/include" -DNDEBUG -I"C:/Users/ybord/Documents/R/win-library/3.6/Rcpp/include/" -I"C:/Users/ybord/Documents/R/win-library/3.6/RcppEigen/include/" -I"C:/Users/ybord/Documents/R/win-library/3.6/RcppEigen/include/unsupported" -I"C:/Users/ybord/Documents/R/win-library/3.6/BH/include" -I"C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/src/" -I"C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/" -I"C:/Users/ybord/Documents/R/win-library/3.6/RcppParallel/include/" -I"C:/Users/ybord/Documents/R/win-library/3.6/rstan/include" -DEIGEN\_NO\_DEBUG -DBOOST\_DISABLE\_ASSERTS -DBOOST\_PENDING\_INTEGER\_LOG2\_HPP -DSTAN\_THREADS -DBOOST\_NO\_AUTO\_PTR -include “C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp” -std=c++1y -O2 -Wall -mtune=core2 -c filef241dfcb3f.cpp -o filef241dfcb3f.o  
c:/Rtools/mingw\_64/bin/g++ -shared -s -static-libgcc -o filef241dfcb3f.dll tmp.def filef241dfcb3f.o C:/Users/ybord/Documents/R/win-library/3.6/rstan/lib/x64/libStanServices.a -LC:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/libs/x64 -lStanHeaders -LC:/Users/ybord/Documents/R/win-library/3.6/RcppParallel/lib/x64 -ltbb -LC:/PROGRA~1/R/R-3.6.3/bin/x64 -lR  
In file included from C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/mat/prob/dirichlet\_log.hpp:5:0,  
from C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/mat.hpp:278,  
from C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math/rev/mat.hpp:12,  
from C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math.hpp:4,  
from C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/src/stan/model/model\_header.hpp:4,  
from filef241dfcb3f.cpp:14:  
C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/mat/prob/dirichlet\_lpmf.hpp: In function ‘stan::return\_type\_t\<T1, T2\> stan::math::dirichlet\_lpmf(const T\_prob&, const T\_prior\_size&)’:  
C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/mat/prob/dirichlet\_lpmf.hpp:60:74: warning: typedef ‘using T\_partials\_vec = struct Eigen::Matrix\<typename stan::partials\_return\_type\<T\_prob, T\_prior\_size\>::type, -1, 1\>’ locally defined but not used [-Wunused-local-typedefs]  
using T\_partials\_vec = typename Eigen::Matrix\<T\_partials\_return, -1, 1\>;  
^  
In file included from C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/mat/prob/poisson\_log\_glm\_log.hpp:5:0,  
from C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/mat.hpp:328,  
from C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math/rev/mat.hpp:12,  
from C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math.hpp:4,  
from C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/src/stan/model/model\_header.hpp:4,  
from filef241dfcb3f.cpp:14:  
C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/mat/prob/poisson\_log\_glm\_lpmf.hpp: In function ‘stan::return\_type\_t\<T\_x, T\_alpha, T\_beta\> stan::math::poisson\_log\_glm\_lpmf(const T\_y&, const T\_x&, const T\_alpha&, const T\_beta&)’:  
C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/mat/prob/poisson\_log\_glm\_lpmf.hpp:55:34: warning: typedef ‘using T\_alpha\_val = std::conditional\_t\<stan::is\_vector::value, Eigen::Array\<typename stan::partials\_return\_type\<T\_alpha\>::type, -1, 1\>, typename stan::partials\_return\_type\<T\_alpha\>::type\>’ locally defined but not used [-Wunused-local-typedefs]  
partials\_return\_t\<T\_alpha\>\>;  
^  
In file included from C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math/rev/mat.hpp:51:0,  
from C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math.hpp:4,  
from C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/src/stan/model/model\_header.hpp:4,  
from filef241dfcb3f.cpp:14:  
C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math/rev/mat/fun/squared\_distance.hpp: In static member function ‘static double stan::math::internal::squared\_distance\_vv\_vari::var\_squared\_distance(const Eigen::Matrix\<stan::math::var, R, C\>&, const Eigen::Matrix\<stan::math::var, R2, C2, (AutoAlign | (((R2 == 1) && (C2 != 1)) ? RowMajor : (((C2 == 1) && (R2 != 1)) ? ColMajor : ColMajor))), R2, C2\>&)’:  
C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math/rev/mat/fun/squared\_distance.hpp:27:54: warning: typedef ‘using idx\_t = using type = Eigen::EigenBase\<Eigen::Matrix\<stan::math::var, -1, -1\> \>::Index’ locally defined but not used [-Wunused-local-typedefs]  
using idx\_t = typename index\_type\<matrix\_v\>::type;  
^  
C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math/rev/mat/fun/squared\_distance.hpp: In static member function ‘static double stan::math::internal::squared\_distance\_vd\_vari::var\_squared\_distance(const Eigen::Matrix\<stan::math::var, R, C\>&, const Eigen::Matrix\<double, R2, C2\>&)’:  
C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math/rev/mat/fun/squared\_distance.hpp:64:54: warning: typedef ‘using idx\_t = using type = Eigen::EigenBase\<Eigen::Matrix\<double, -1, -1\> \>::Index’ locally defined but not used [-Wunused-local-typedefs]  
using idx\_t = typename index\_type\<matrix\_d\>::type;  
^  
filef241dfcb3f.cpp: In member function ‘virtual void modelf24739d3ddc\_73fc79f8b1915e8208c736914c86d1a1\_namespace::modelf24739d3ddc\_73fc79f8b1915e8208c736914c86d1a1::transform\_inits(const stan::io::var\_context&, std::vector&, std::vector&, std::ostream\*) const’:  
filef241dfcb3f.cpp:108:24: warning: typedef ‘local\_scalar\_t\_\_’ locally defined but not used [-Wunused-local-typedefs]  
typedef double local\_scalar\_t\_\_;  
^  
In file included from C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math/rev/core.hpp:46:0,  
from C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math/rev/mat.hpp:6,  
from C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math.hpp:4,  
from C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/src/stan/model/model\_header.hpp:4,  
from filef241dfcb3f.cpp:14:  
C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math/rev/core/set\_zero\_all\_adjoints.hpp: At global scope:  
C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math/rev/core/set\_zero\_all\_adjoints.hpp:14:13: warning: ‘void stan::math::set\_zero\_all\_adjoints()’ defined but not used [-Wunused-function]  
static void set\_zero\_all\_adjoints()

---

<div class="post-metadata">

**Author:** ![andrjohns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrjohns/32/15297_2.png) [@andrjohns](https://discourse.mc-stan.org/u/andrjohns)\
**Post date:** [September 7, 2020, 9:07am UTC](https://discourse.mc-stan.org/t/error-caused-by-missing-stan-header/17849/5 "2020-09-07T09:07:28Z")

</div>

Those are all compiler warnings, rather than actual errors. We need to add compiler flags to turn them off so that only the error is reported.

Can you run:

```
cat("CXX14FLAGS += -Wno-unused-local-typedefs -Wno-unused-function",file = "~/.R/Makevars.win", sep = "\n", append = TRUE)

```

And then re-run your model?

---

<div class="post-metadata">

**Author:** ![ybordag](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ybordag/32/9243_2.png) [@ybordag](https://discourse.mc-stan.org/u/ybordag)\
**Post date:** [September 7, 2020, 6:29pm UTC](https://discourse.mc-stan.org/t/error-caused-by-missing-stan-header/17849/6 "2020-09-07T18:29:54Z")

</div>

I did not have a makevars file to begin with so I created one. After the flag was added, I still got the same error when I ran my code:

test = stan(“C:/Users/ybord/Documents/School/2020-2021/Covid-19 Project/Code/seir-reopening-all-fit/SIER\_Reopening\_All\_fit.stan”,  
data = stan\_d,  
pars = params\_monitor,  
chains = 1, iter = 10)  
Error in compileCode(f, code, language = language, verbose = verbose) :  
Compilation ERROR, function(s)/method(s) not created! In file included from C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/mat/prob/dirichlet\_log.hpp:5:0,  
from C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/mat.hpp:278,  
from C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math/rev/mat.hpp:12,  
from C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math.hpp:4,  
from C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/src/stan/model/model\_header.hpp:4,  
from file389444f83ccd.cpp:14:  
C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/mat/prob/dirichlet\_lpmf.hpp: In function ‘stan::return\_type\_t\<T1, T2\> stan::math::dirichlet\_lpmf(const T\_prob&, const T\_prior\_size&)’:  
C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/mat/prob/dirichlet\_l  
In addition: Warning messages:  
1: In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :  
‘C:/Rtools/mingw\_/bin/g++’ not found  
2: In system(cmd, intern = !verbose) :  
running command ‘C:/PROGRA~1/R/R-3.6.3/bin/x64/R CMD SHLIB file389444f83ccd.cpp 2\> file389444f83ccd.cpp.err.txt’ had status 1  
Error in sink(type = “output”) : invalid connection

---

<div class="post-metadata">

**Author:** ![andrjohns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrjohns/32/15297_2.png) [@andrjohns](https://discourse.mc-stan.org/u/andrjohns)\
**Post date:** [September 8, 2020, 1:55am UTC](https://discourse.mc-stan.org/t/error-caused-by-missing-stan-header/17849/7 "2020-09-08T01:55:51Z")

</div>

This might be related to issues we’re currently having with the `inline` package on windows. Can you try installing the following patched version and re-rerunning your model?

```
install.packages("https://github.com/bgoodri/inline/archive/master.tar.gz", 
                 repos = NULL, type = "source")

```

Also, can you run:

```
readLines("~/.R/Makevars.win")

```

And post the output?

---

<div class="post-metadata">

**Author:** ![ybordag](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ybordag/32/9243_2.png) [@ybordag](https://discourse.mc-stan.org/u/ybordag)\
**Post date:** [September 8, 2020, 2:12am UTC](https://discourse.mc-stan.org/t/error-caused-by-missing-stan-header/17849/8 "2020-09-08T02:12:25Z")

</div>

I installed the package and reran everything

test = stan(“C:/Users/ybord/Documents/School/2020-2021/Covid-19 Project/Code/seir-reopening-all-fit/SIER\_Reopening\_All\_fit.stan”,  
data = stan\_d,  
pars = params\_monitor,  
chains = 1, iter = 10)

make cmd is  
make -f “C:/PROGRA~1/R/R-3.6.3/etc/x64/Makeconf” -f “C:/PROGRA~1/R/R-3.6.3/share/make/winshlib.mk” -f “C:\Users\ybord\AppData\Local\Temp\RtmpILLCgg\Makevars41ec18d23d79” CXX=‘(CXX11) (CXX11STD)’ CXXFLAGS=‘(CXX11FLAGS)' CXXPICFLAGS='(CXX11PICFLAGS)’ SHLIB\_LDFLAGS=‘(SHLIB\_CXX11LDFLAGS)' SHLIB\_LD='(SHLIB\_CXX11LD)’ SHLIB=“file41ec4ce47ee.dll” WIN=64 TCLBIN=64 OBJECTS=“file41ec4ce47ee.o”

make would use  
c:/Rtools/mingw\_64/bin/g++ -std=gnu++11 -I"C:/PROGRA~1/R/R-3.6.3/include" -DNDEBUG -I"C:/Users/ybord/Documents/R/win-library/3.6/Rcpp/include/" -I"C:/Users/ybord/Documents/R/win-library/3.6/RcppEigen/include/" -I"C:/Users/ybord/Documents/R/win-library/3.6/RcppEigen/include/unsupported" -I"C:/Users/ybord/Documents/R/win-library/3.6/BH/include" -I"C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/src/" -I"C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/" -I"C:/Users/ybord/Documents/R/win-library/3.6/RcppParallel/include/" -I"C:/Users/ybord/Documents/R/win-library/3.6/rstan/include" -DEIGEN\_NO\_DEBUG -DBOOST\_DISABLE\_ASSERTS -DBOOST\_PENDING\_INTEGER\_LOG2\_HPP -DSTAN\_THREADS -DBOOST\_NO\_AUTO\_PTR -include “C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp” -std=c++1y -O2 -Wall -mtune=core2 -c file41ec4ce47ee.cpp -o file41ec4ce47ee.o  
if test “zfile41ec4ce47ee.o” != “z”; then   
if test -e “file41ec4ce47ee-win.def”; then   
echo c:/Rtools/mingw\_64/bin/g++ -shared -s -static-libgcc -o file41ec4ce47ee.dll file41ec4ce47ee-win.def file41ec4ce47ee.o “C:/Users/ybord/Documents/R/win-library/3.6/rstan/lib/x64/libStanServices.a” -L"C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/ybord/Documents/R/win-library/3.6/RcppParallel/lib/x64" -ltbb -L"C:/PROGRA~1/R/R-3.6.3/bin/x64" -lR ;   
c:/Rtools/mingw\_64/bin/g++ -shared -s -static-libgcc -o file41ec4ce47ee.dll file41ec4ce47ee-win.def file41ec4ce47ee.o “C:/Users/ybord/Documents/R/win-library/3.6/rstan/lib/x64/libStanServices.a” -L"C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/ybord/Documents/R/win-library/3.6/RcppParallel/lib/x64" -ltbb -L"C:/PROGRA~1/R/R-3.6.3/bin/x64" -lR ;   
else   
echo EXPORTS \> tmp.def;   
c:/Rtools/mingw\_64/bin/nm file41ec4ce47ee.o | sed -n ‘s/^.\* [BCDRT] / /p’ | sed -e ‘/[.]refptr[.]/d’ -e ‘/[.]weak[.]/d’ | sed ‘s/[^][^]\*/“&”/g’ \>\> tmp.def;   
echo c:/Rtools/mingw\_64/bin/g++ -shared -s -static-libgcc -o file41ec4ce47ee.dll tmp.def file41ec4ce47ee.o “C:/Users/ybord/Documents/R/win-library/3.6/rstan/lib/x64/libStanServices.a” -L"C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/ybord/Documents/R/win-library/3.6/RcppParallel/lib/x64" -ltbb -L"C:/PROGRA~1/R/R-3.6.3/bin/x64" -lR ;   
c:/Rtools/mingw\_64/bin/g++ -shared -s -static-libgcc -o file41ec4ce47ee.dll tmp.def file41ec4ce47ee.o “C:/Users/ybord/Documents/R/win-library/3.6/rstan/lib/x64/libStanServices.a” -L"C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/ybord/Documents/R/win-library/3.6/RcppParallel/lib/x64" -ltbb -L"C:/PROGRA~1/R/R-3.6.3/bin/x64" -lR ;   
rm -f tmp.def;   
fi   
fi  
Error in compileCode(f, code, language = language, verbose = verbose) :  
from C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/src/stan/model/model\_header.hpp:4, from file41ec4ce47ee.cpp:14:C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math/rev/core/set\_zero\_all\_adjoints.hpp:14:13: warning: ‘void stan::math::set\_zero\_all\_adjoints()’ defined but not used [-Wunused-function] static void set\_zero\_all\_adjoints() { ^make: \*\*\* [C:/PROGRA~1/R/R-3.6.3/etc/x64/Makeconf:215: file41ec4ce47ee.o] Error 1  
In addition: Warning message:  
In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :  
‘C:/Rtools/mingw\_/bin/g++’ not found  
Error in sink(type = “output”) : invalid connection

And this is my output for the Makevars.win

> readLines(“~/.R/Makevars.win”)  
> [1] “CXX14FLAGS += -Wno-unused-local-typedefs -Wno-unused-function”

---

<div class="post-metadata">

**Author:** ![andrjohns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrjohns/32/15297_2.png) [@andrjohns](https://discourse.mc-stan.org/u/andrjohns)\
**Post date:** [September 8, 2020, 2:16am UTC](https://discourse.mc-stan.org/t/error-caused-by-missing-stan-header/17849/9 "2020-09-08T02:16:28Z")

</div>

Can you change the Makevars file to:

```
CXX14FLAGS = -Wno-unused-local-typedefs -Wno-unused-function

```

(i.e. remove the `+` operator) and run again?

---

<div class="post-metadata">

**Author:** ![andrjohns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrjohns/32/15297_2.png) [@andrjohns](https://discourse.mc-stan.org/u/andrjohns)\
**Post date:** [September 8, 2020, 2:33am UTC](https://discourse.mc-stan.org/t/error-caused-by-missing-stan-header/17849/10 "2020-09-08T02:33:57Z")

</div>

If that makes no change, can you try running:

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

```

And post the result?

---

<div class="post-metadata">

**Author:** ![ybordag](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ybordag/32/9243_2.png) [@ybordag](https://discourse.mc-stan.org/u/ybordag)\
**Post date:** [September 8, 2020, 3:17am UTC](https://discourse.mc-stan.org/t/error-caused-by-missing-stan-header/17849/11 "2020-09-08T03:17:12Z")

</div>

I first tried to change the makevars file, but I got the same output

I then ran your next suggestion and still got the following output

make cmd is  
make -f “C:/PROGRA~1/R/R-3.6.3/etc/x64/Makeconf” -f “C:/PROGRA~1/R/R-3.6.3/share/make/winshlib.mk” -f “C:\Users\ybord\AppData\Local\Temp\RtmpILLCgg\Makevars41ec19276a25” CXX=’(CXX11) (CXX11STD)’ CXXFLAGS=’(CXX11FLAGS)' CXXPICFLAGS='(CXX11PICFLAGS)’ SHLIB\_LDFLAGS=’(SHLIB\_CXX11LDFLAGS)' SHLIB\_LD='(SHLIB\_CXX11LD)’ SHLIB=“file41ec584834e8.dll” WIN=64 TCLBIN=64 OBJECTS=“file41ec584834e8.o”

make would use  
c:/Rtools/mingw\_64/bin/g++ -std=gnu++11 -I"C:/PROGRA~1/R/R-3.6.3/include" -DNDEBUG -I"C:/Users/ybord/Documents/R/win-library/3.6/Rcpp/include/" -I"C:/Users/ybord/Documents/R/win-library/3.6/RcppEigen/include/" -I"C:/Users/ybord/Documents/R/win-library/3.6/RcppEigen/include/unsupported" -I"C:/Users/ybord/Documents/R/win-library/3.6/BH/include" -I"C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/src/" -I"C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/" -I"C:/Users/ybord/Documents/R/win-library/3.6/RcppParallel/include/" -I"C:/Users/ybord/Documents/R/win-library/3.6/rstan/include" -DEIGEN\_NO\_DEBUG -DBOOST\_DISABLE\_ASSERTS -DBOOST\_PENDING\_INTEGER\_LOG2\_HPP -DSTAN\_THREADS -DBOOST\_NO\_AUTO\_PTR -include “C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp” -std=c++1y -O2 -Wall -mtune=core2 -c file41ec584834e8.cpp -o file41ec584834e8.o  
if test “zfile41ec584834e8.o” != “z”; then   
if test -e “file41ec584834e8-win.def”; then   
echo c:/Rtools/mingw\_64/bin/g++ -shared -s -static-libgcc -o file41ec584834e8.dll file41ec584834e8-win.def file41ec584834e8.o “C:/Users/ybord/Documents/R/win-library/3.6/rstan/lib/x64/libStanServices.a” -L"C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/ybord/Documents/R/win-library/3.6/RcppParallel/lib/x64" -ltbb -L"C:/PROGRA~1/R/R-3.6.3/bin/x64" -lR ;   
c:/Rtools/mingw\_64/bin/g++ -shared -s -static-libgcc -o file41ec584834e8.dll file41ec584834e8-win.def file41ec584834e8.o “C:/Users/ybord/Documents/R/win-library/3.6/rstan/lib/x64/libStanServices.a” -L"C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/ybord/Documents/R/win-library/3.6/RcppParallel/lib/x64" -ltbb -L"C:/PROGRA~1/R/R-3.6.3/bin/x64" -lR ;   
else   
echo EXPORTS \> tmp.def;   
c:/Rtools/mingw\_64/bin/nm file41ec584834e8.o | sed -n ‘s/^.\* [BCDRT] / /p’ | sed -e ‘/[.]refptr[.]/d’ -e ‘/[.]weak[.]/d’ | sed ‘s/[^][^]\*/"&"/g’ \>\> tmp.def;   
echo c:/Rtools/mingw\_64/bin/g++ -shared -s -static-libgcc -o file41ec584834e8.dll tmp.def file41ec584834e8.o “C:/Users/ybord/Documents/R/win-library/3.6/rstan/lib/x64/libStanServices.a” -L"C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/ybord/Documents/R/win-library/3.6/RcppParallel/lib/x64" -ltbb -L"C:/PROGRA~1/R/R-3.6.3/bin/x64" -lR ;   
c:/Rtools/mingw\_64/bin/g++ -shared -s -static-libgcc -o file41ec584834e8.dll tmp.def file41ec584834e8.o “C:/Users/ybord/Documents/R/win-library/3.6/rstan/lib/x64/libStanServices.a” -L"C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/ybord/Documents/R/win-library/3.6/RcppParallel/lib/x64" -ltbb -L"C:/PROGRA~1/R/R-3.6.3/bin/x64" -lR ;   
rm -f tmp.def;   
fi   
fi  
Error in compileCode(f, code, language = language, verbose = verbose) :  
from C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/src/stan/model/model\_header.hpp:4, from file41ec584834e8.cpp:14:C:/Users/ybord/Documents/R/win-library/3.6/StanHeaders/include/stan/math/rev/core/set\_zero\_all\_adjoints.hpp:14:13: warning: ‘void stan::math::set\_zero\_all\_adjoints()’ defined but not used [-Wunused-function] static void set\_zero\_all\_adjoints() { ^make: \*\*\* [C:/PROGRA~1/R/R-3.6.3/etc/x64/Makeconf:215: file41ec584834e8.o] Error 1  
In addition: Warning message:  
In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :  
‘C:/Rtools/mingw\_/bin/g++’ not found  
Error in sink(type = “output”) : invalid connection

---

<div class="post-metadata">

**Author:** ![andrjohns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrjohns/32/15297_2.png) [@andrjohns](https://discourse.mc-stan.org/u/andrjohns)\
**Post date:** [September 8, 2020, 3:20am UTC](https://discourse.mc-stan.org/t/error-caused-by-missing-stan-header/17849/12 "2020-09-08T03:20:19Z")

</div>

Can you restart R and run:

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

```

---

<div class="post-metadata">

**Author:** ![ybordag](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ybordag/32/9243_2.png) [@ybordag](https://discourse.mc-stan.org/u/ybordag)\
**Post date:** [September 8, 2020, 3:21am UTC](https://discourse.mc-stan.org/t/error-caused-by-missing-stan-header/17849/13 "2020-09-08T03:21:33Z")

</div>

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

I don’t get an output after this. Is this error a result of my model after all?

---

<div class="post-metadata">

**Author:** ![andrjohns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrjohns/32/15297_2.png) [@andrjohns](https://discourse.mc-stan.org/u/andrjohns)\
**Post date:** [September 8, 2020, 3:22am UTC](https://discourse.mc-stan.org/t/error-caused-by-missing-stan-header/17849/14 "2020-09-08T03:22:50Z")

</div>

Yes, it looks like your toolchain/compiler is fine but something with your model is causing an error. Are you able to post your model?

---

<div class="post-metadata">

**Author:** ![ybordag](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ybordag/32/9243_2.png) [@ybordag](https://discourse.mc-stan.org/u/ybordag)\
**Post date:** [September 8, 2020, 3:33am UTC](https://discourse.mc-stan.org/t/error-caused-by-missing-stan-header/17849/15 "2020-09-08T03:33:34Z")

</div>

I am trying to fit multiple sets of parameters at once to a compartmental model. I was able to get a piece of code running that only fit one set of data to the model:

functions {  
// This largely follows the deSolve package, but also includes the x\_r and x\_i variables.  
// These variables are used in the background.  
// params = [beta, sigma, gamma, delta]  
// y = [S, E, I, R]

real[] SIER(real t,  
real[] y,  
real[] params,  
real[] x\_r,  
int[] x\_i) {

```
  // Our compartments
  real S = y[1];
  real E = y[2];
  real I = y[3];
  real R = y[4];

  // Our model parameters
  real beta = params[1];
  real sigma = params[2];
  real gamma = params[3];
  real delta = params[4];
  real dydt[4];
  dydt[1] = - beta * S * I;
  dydt[2] = beta * S * I - sigma * E;
  dydt[3] = sigma * E - (gamma + delta) * I;
  dydt[4] = gamma * I;
  return dydt;
}

```

}

data {  
int\<lower = 1\> n\_obs; // Number of days sampled  
int\<lower = 1\> n\_params; // Number of model parameters  
int\<lower = 1\> n\_difeq; // Number of differential equations in the system  
int\<lower = 100\> n\_pop; // This is to estimate the susceptible population  
real\<lower = 0\> deaths[n\_obs]; // The death data  
real t0; // Initial time point (zero)  
real ts[n\_obs]; // Time index  
}

transformed data {  
real x\_r[0];  
int x\_i[0];  
}

parameters {  
real\<lower = 0, upper = 1\> params[n\_params]; // Model parameters  
//int\<lower = 0\> S0; // Initial estimate of hosts susceptible  
real\<lower = 0\> E0; // Initial estimate of infected hosts  
real\<lower = 0\> I0; // Initial estimate of exposed hosts  
real\<lower = 0, upper = 1\> prop\_sus; // Estimated inverse of proportion of susceptible individuals  
real\<lower = 0\> phi; // Variance of model  
}

transformed parameters{  
real y\_hat[n\_obs, n\_difeq]; // Output from the ODE solver  
real y0[n\_difeq]; // Initial conditions for S, E, I, R  
vector[n\_obs] approx\_deaths;  
y0[1] = n\_pop \* prop\_sus;  
y0[2] = E0;  
y0[3] = I0;  
y0[4] = 0;  
y\_hat = integrate\_ode\_bdf(SIER, y0, t0, ts, params, x\_r, x\_i, 1e-9, 1e-5, 1e6);  
approx\_deaths = to\_vector(y\_hat[,3]) \* params[4];  
}

model {  
params ~ beta(1, 20); //constrained to be 0-1  
prop\_sus ~ beta(10, 6); //constrained to be 0-1  
E0 ~ normal(10, 2); //constrained to be positive.  
I0 ~ normal(10, 2); //constrained to be positive.  
phi ~ cauchy(15, 5); //constrained to be positive  
deaths ~ normal(approx\_deaths, phi);  
}

generated quantities {  
// Generate predicted data over the whole time series:  
vector[n\_obs] pred\_deaths;  
pred\_deaths = to\_vector(integrate\_ode\_bdf(SIER, y0, t0, ts, params, x\_r, x\_i, 1e-9, 1e-5, 1e6)[,3]) \* params[4];  
}

which works reasonably well. This is the code I am currently trying to run:

functions {  
// This largely follows the deSolve package, but also includes the x\_r and x\_i variables.  
// These variables are used in the background.  
// params = [beta, sigma, gamma, delta]  
// y = [S, E, I, R]

real[] SEIR(real t,  
real[] y,  
real[] params,  
real[] x\_r,  
int[] x\_i) {  
// Our compartments  
real S = y[1];  
real E = y[2];  
real I = y[3];  
real R = y[4];

```
  // Our model parameters
  real beta = params[1];
  real sigma = params[2];
  real gamma = params[3];
  real delta = params[4];
  real dydt[4];

  dydt[1] = - beta * S * I;
  dydt[2] = beta * S * I - sigma * E;
  dydt[3] = sigma * E - (gamma + delta) * I;
  dydt[4] = gamma * I;
  return dydt;
}

```

}

data {

int\<lower = 1\> n\_obs; // Number of days sampled  
int\<lower = 1\> n\_states; // Number of state data provided  
int\<lower = 1\> n\_params; // Number of model parameters  
int\<lower = 1\> n\_difeq; // Number of differential equations in the system  
int\<lower = 100\> n\_pop[n\_states]; // This is to estimate the susceptible population  
real\<lower = 0\> deaths[n\_states, n\_obs]; // The death data  
real t0; // Initial time point (zero)  
real ts[n\_obs]; // Time index

}

transformed data {

real x\_r[0];  
int x\_i[0];

}

parameters {

real\<lower = 0, upper = 1\> params[n\_states, n\_params]; // Model parameters  
//int\<lower = 0\> S0; // Initial estimate of hosts susceptible  
real\<lower = 0\> I0[n\_states]; // Initial estimate of infected hosts  
real\<lower = 0\> E0[n\_states]; // Initial estimate of exposed hosts  
real\<lower = 0, upper = 1\> prop\_sus[n\_states]; // Estimated inverse of proportion of susceptible individuals  
real\<lower = 0\> phi[n\_states];

}

transformed parameters{

real y\_hat[n\_states, n\_obs, n\_difeq]; // Output from the ODE solver  
real y0[n\_states, n\_difeq]; // Initial conditions for S, E, I, R  
vector[n\_obs] approx\_deaths[n\_states];

for (i in 1:n\_states) {  
y0[i][1] = n\_pop[i] \* prop\_sus[i];  
y0[i][2] = E0[i];  
y0[i][3] = I0[i];  
y0[i][4] = 0;

```
y_hat[i] = integrate_ode_bdf(SEIR, y0[i], t0, ts, params[i], x_r, x_i, 1e-9, 1e-5, 1e6);
approx_deaths[i] = to_vector(y_hat[i][,3]) * params[i][4];

```

}  
}

model {

prop\_sus ~ beta(10, 6); //constrained to be 0-1  
E0 ~ normal(10, 2); //constrained to be positive.  
I0 ~ normal(10, 2); //constrained to be positive.  
phi ~ cauchy(15, 5); //constrained to be positive

for (i in 1:n\_states) {  
params[i] ~ beta(1, 20); //constrained to be 0-1  
deaths[i] ~ normal(approx\_deaths[i], phi[i]);  
}  
}

generated quantities {  
// Generate predicted data over the whole time series:  
vector[n\_obs] pred\_deaths[n\_states];

for (i in 1:n\_states) {  
pred\_deaths[i] = to\_vector(integrate\_ode\_bdf(SEIR, y0[i], t0, ts, params[i], x\_r, x\_i, 1e-9, 1e-5, 1e6)[,3]) \* params[i][4];  
}  
}

Thanks!

---

<div class="post-metadata">

**Author:** ![andrjohns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrjohns/32/15297_2.png) [@andrjohns](https://discourse.mc-stan.org/u/andrjohns)\
**Post date:** [September 8, 2020, 3:38am UTC](https://discourse.mc-stan.org/t/error-caused-by-missing-stan-header/17849/16 "2020-09-08T03:38:40Z")

</div>

Thanks! I can reproduce the error on my system, which means there’s definitely something to be fixed!

Thanks for finding this, I’ll have a closer look at where the issue is coming from and keep you updated

---

<div class="post-metadata">

**Author:** ![andrjohns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrjohns/32/15297_2.png) [@andrjohns](https://discourse.mc-stan.org/u/andrjohns)\
**Post date:** [September 8, 2020, 4:44am UTC](https://discourse.mc-stan.org/t/error-caused-by-missing-stan-header/17849/17 "2020-09-08T04:44:46Z")

</div>

I’m able to compile your model in cmdstanR, which uses a more recent version of Stan, so I’d recommend that you run your models through that in the mean time.

The Getting Started guide is available here: [https://mc-stan.org/cmdstanr/articles/cmdstanr.html](https://mc-stan.org/cmdstanr/articles/cmdstanr.html)

But many people are running into issues with getting it installed and up-and-running.

Here’s what worked for me:

Install the mingw32-make package and update the PATH:

```
processx::run(
    "pacman",
    args = c("-Syu", "mingw-w64-x86_64-make","--noconfirm"),
    wd = file.path(Sys.getenv("RTOOLS40_HOME"), "usr", "bin"),
    echo = TRUE
)
write('PATH="${RTOOLS40_HOME}\\usr\\bin;${RTOOLS40_HOME}\\mingw64\\bin;${PATH}"', file = "~/.Renviron", append = FALSE)

```

Restart R and run:

```
install.packages("cmdstanr", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))

library(cmdstanr)
install_cmdstan()

```

If the `install_cmdstan()` finishes without an error, then you’re good to start running models. If it does error, try running:

```
setwd(".cmdstanr/cmdstan-2.24.1/")
processx::run(
    "mingw32-make",args="clean"
)
processx::run(
    "mingw32-make",args=c("-j4","build"),
    echo=T
)

```

If that runs without an error, then restart R and you’re ready to run your Stan model!

---

<div class="post-metadata">

**Author:** ![ybordag](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ybordag/32/9243_2.png) [@ybordag](https://discourse.mc-stan.org/u/ybordag)\
**Post date:** [September 12, 2020, 11:07pm UTC](https://discourse.mc-stan.org/t/error-caused-by-missing-stan-header/17849/18 "2020-09-12T23:07:28Z")

</div>

I was able to compile it successfully, thank you for the help!

I still don’t quite understand why the code wouldn’t compile. Is there anything I should try to keep in mind for future projects to avoid these compilation issues?

---

<div class="post-metadata">

**Author:** ![andrjohns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrjohns/32/15297_2.png) [@andrjohns](https://discourse.mc-stan.org/u/andrjohns)\
**Post date:** [September 13, 2020, 1:32pm UTC](https://discourse.mc-stan.org/t/error-caused-by-missing-stan-header/17849/19 "2020-09-13T13:32:14Z")

</div>

This was just a bug specific to this version of Stan, it’s not really something predictable that you have to worry about

---

<div class="post-metadata">

**Author:** ![royemanuel](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/royemanuel/32/7965_2.png) [@royemanuel](https://discourse.mc-stan.org/u/royemanuel)\
**Post date:** [September 29, 2020, 1:20pm UTC](https://discourse.mc-stan.org/t/error-caused-by-missing-stan-header/17849/20 "2020-09-29T13:20:21Z")

</div>

I am getting similar errors (in the original post - dirichlet\_log.hpp:5:0, mat.hpp:278, mat.hpp:12, math.hpp:4, model\_header.hpp:4, dirchlet\_lpmf.hpp:6 ) using the 8schools model. Installing CmdStan is not an option for me. Is there another workaround?

— UPDATE —  
Although the errors were the same, this was an unrelated problem. Dealing with a Citrix server on a non-internet system. Simplified my package installation structure and this fixed the problem.
