# Cannot compile packages that depend on RStan with the latest version of Stanheaders

**URL:** <https://discourse.mc-stan.org/t/cannot-compile-packages-that-depend-on-rstan-with-the-latest-version-of-stanheaders/9297>\
**Category:** Developers\
**Tags:** rstan\
**Created:** [June 17, 2019, 3:24pm UTC](https://discourse.mc-stan.org/t/cannot-compile-packages-that-depend-on-rstan-with-the-latest-version-of-stanheaders/9297 "2019-06-17T15:24:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jure\_Demsar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jure_demsar/32/4130_2.png) [@Jure\_Demsar](https://discourse.mc-stan.org/u/Jure_Demsar)\
**Post date:** [June 17, 2019, 3:24pm UTC](https://discourse.mc-stan.org/t/cannot-compile-packages-that-depend-on-rstan-with-the-latest-version-of-stanheaders/9297/1 "2019-06-17T15:24:59Z")

</div>

Hi,

I have been developing a package that depends on RStan for a while now, the package incorporates stan models the same way as rstanarm ([https://mc-stan.org/rstantools/articles/minimal-rstan-package.html](https://mc-stan.org/rstantools/articles/minimal-rstan-package.html)). Everything was working fine until recently when StanHeaders update 2.18.1-10 came out, with this update I am no longer able to compile the package on Windows and Linux (I am able to compile it on mac though). If I revert StanHeaders back to 2.18.1 I am able to compile everything again. I also checked if this is an issue with my package but it seems like it is not, if I download rstanarm from GitHub and try to compile it locally the issues are the same (I can compile rstanarm with StanHeaders 2.18.1 but not with 2.18.2-10).

The main problem with this is that CRAN auto checks use the latest version of StanHeaders (2.18.2-10) when test compiling, so when I try to upload my package to CRAN it gets rejected beacuse of this issue with StanHeaders .

Thanks!

---

<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 17, 2019, 3:46pm UTC](https://discourse.mc-stan.org/t/cannot-compile-packages-that-depend-on-rstan-with-the-latest-version-of-stanheaders/9297/2 "2019-06-17T15:46:38Z")

</div>

This is most likely due to the lack of specifying the C++14 stuff in your src/Makevars and src/Makevars.win files. Do you have a link to the package repository?

---

<div class="post-metadata">

**Author:** ![Jure\_Demsar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jure_demsar/32/4130_2.png) [@Jure\_Demsar](https://discourse.mc-stan.org/u/Jure_Demsar)\
**Post date:** [June 17, 2019, 4:17pm UTC](https://discourse.mc-stan.org/t/cannot-compile-packages-that-depend-on-rstan-with-the-latest-version-of-stanheaders/9297/3 "2019-06-17T16:17:27Z")

</div>

This is the link: [https://github.com/bstatcomp/bayes4psy](https://github.com/bstatcomp/bayes4psy).

Below is the content of Makevars and Makevars.win, thanks!

**Makevars**

```
    STANHEADERS_SRC = `"$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"`
    PKG_CPPFLAGS = -I"../inst/include" -I"$(STANHEADERS_SRC)" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -DBOOST_MATH_OVERFLOW_ERROR_POLICY=errno_on_error

    SOURCES = $(wildcard stan_files/*.stan)
    OBJECTS = $(SOURCES:.stan=.o) init.o

    all: $(SHLIB)
    		@if test -e "/usr/bin/install_name_tool" && test -e "/usr/local/clang4/lib/libc++.1.dylib" && test -e "/usr/lib/libc++.1.dylib"; then /usr/bin/install_name_tool -change /usr/local/clang4/lib/libc++.1.dylib /usr/lib/libc++.1.dylib $(SHLIB); fi

    clean:
    		rm -rf stan_files/*.o
    		rm -rf *.so *.o
    		rm -rf stan_files/*.cc
    		rm -rf stan_files/*.hpp

    %.cc: %.stan
    		"$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "source(file.path('..', 'tools', 'make_cc.R')); make_cc(commandArgs(TRUE))" $<

.phony: all clean

```

**Makevars.win**

```
STANHEADERS_SRC = `"$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"`
BOOST_NOT_IN_BH_SRC = `"$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" --vanilla -e "cat(system.file('include', 'boost_not_in_BH', package = 'rstan'))"`
PKG_CPPFLAGS = -I"../inst/include" -I"$(STANHEADERS_SRC)" -I"$(BOOST_NOT_IN_BH_SRC)" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -DBOOST_NO_CXX11_RVALUE_REFERENCES

CXX_STD = CXX11
SOURCES = $(wildcard stan_files/*.stan)
OBJECTS = $(SOURCES:.stan=.o) init.o

all: $(SHLIB)

clean:
		RM -rf stan_files/*.o
		RM -rf *.so *.o
		RM -rf stan_files/*.cc
		RM -rf stan_files/*.hpp

%.cc: %.stan
				"$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "source(file.path('..', 'tools', 'make_cc.R')); make_cc(commandArgs(TRUE))" $<

				
.phony: clean
```

---

<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 17, 2019, 5:33pm UTC](https://discourse.mc-stan.org/t/cannot-compile-packages-that-depend-on-rstan-with-the-latest-version-of-stanheaders/9297/4 "2019-06-17T17:33:03Z")

</div>

Yes, in both files you need `CXX_STD = CXX14 and ideally also`CXX14STD = -std=c++1y`.

---

<div class="post-metadata">

**Author:** ![Jure\_Demsar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jure_demsar/32/4130_2.png) [@Jure\_Demsar](https://discourse.mc-stan.org/u/Jure_Demsar)\
**Post date:** [June 17, 2019, 6:13pm UTC](https://discourse.mc-stan.org/t/cannot-compile-packages-that-depend-on-rstan-with-the-latest-version-of-stanheaders/9297/5 "2019-06-17T18:13:47Z")

</div>

This solved my problems, thanks!
