# Model\_header.hpp:4:25: fatal error: stan/math.hpp: No such file or directory

**URL:** <https://discourse.mc-stan.org/t/model-header-hpp25-fatal-error-stan-math-hpp-no-such-file-or-directory/7538>\
**Category:** RStan\
**Created:** [January 31, 2019, 3:19pm UTC](https://discourse.mc-stan.org/t/model-header-hpp25-fatal-error-stan-math-hpp-no-such-file-or-directory/7538 "2019-01-31T15:19:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jozsef\_Hegedus](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jozsef_hegedus/32/3825_2.png) [@Jozsef\_Hegedus](https://discourse.mc-stan.org/u/Jozsef_Hegedus)\
**Post date:** [January 31, 2019, 3:19pm UTC](https://discourse.mc-stan.org/t/model-header-hpp25-fatal-error-stan-math-hpp-no-such-file-or-directory/7538/1 "2019-01-31T15:19:25Z")

</div>

Dear STAN Modellers,

I have the error shown below when I try to “fit” a model (simple 2D GMM).

Could you please give me a hint on how I can fix this ?

Thank you,  
Jozsef

```
Error in compileCode(f, code, language = language, verbose = verbose) :
  Compilation ERROR, function(s)/method(s) not created! In file included from file3148752a73.cpp:8:0:
/usr/local/lib/R/site-library/StanHeaders/include/src/stan/model/model_header.hpp:4:25: fatal error: stan/math.hpp: No such file or directory
 #include <stan/math.hpp>
                         ^
compilation terminated.
make: *** [file3148752a73.o] Error 1
In addition: Warning message:
In system(cmd, intern = !verbose) :
  running command '/usr/lib/R/bin/R CMD SHLIB file3148752a73.cpp 2> file3148752a73.cpp.err.txt' had status 1
Error in sink(type = "output") : invalid connection

```

If I execute the following code:

```
fit <- stan(file='gmm2D.stan', data=input_data, chains=4, seed=483892929, refresh=2000)

```

My environment is the following :

- Operating System : Debian 8
- RStan Version : 2.18.0
- Output of `writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars")))`

```
STANHEADERS_SRC = `"$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"`
CXX_STD = CXX14

CXX14 = g++ -std=c++1y

CXX14FLAGS=-O3 -march=native -mtune=native -fPIC

PKG_CPPFLAGS = -I"../inst/include" -I"$(STANHEADERS_SRC)" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION
SHLIB_LDFLAGS = $(SHLIB_CXXLDFLAGS)
SHLIB_LD = $(SHLIB_CXXLD)

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

.phony: all

```

- Output of `devtools::session_info("rstan")`

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/f/f5f4c6bf5f2a02a98846592ec87fe8d827789824.png)

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/2/22dca48fac13460f5614e1c7991762983c51943f.png)

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/9/94d2f32d32815247fa744dfa972cf948267e5f8c.png)

If you are reporting a bug (thank you!) please use the issue tracker ([github.com/stan-dev/rstan/issues](http://github.com/stan-dev/rstan/issues)) instead of the forums.

---

<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:** [January 31, 2019, 3:57pm UTC](https://discourse.mc-stan.org/t/model-header-hpp25-fatal-error-stan-math-hpp-no-such-file-or-directory/7538/2 "2019-01-31T15:57:18Z")

</div>

It is not finding your StanHeaders package. I would install the latest RStan.

---

<div class="post-metadata">

**Author:** ![Jozsef\_Hegedus](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jozsef_hegedus/32/3825_2.png) [@Jozsef\_Hegedus](https://discourse.mc-stan.org/u/Jozsef_Hegedus)\
**Post date:** [January 31, 2019, 4:36pm UTC](https://discourse.mc-stan.org/t/model-header-hpp25-fatal-error-stan-math-hpp-no-such-file-or-directory/7538/3 "2019-01-31T16:36:59Z")

</div>

Hi @bgoodri,

Let me check what is going on, and check the RStan installation.

Cheers

Jozsef

---

<div class="post-metadata">

**Author:** ![Jozsef\_Hegedus](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jozsef_hegedus/32/3825_2.png) [@Jozsef\_Hegedus](https://discourse.mc-stan.org/u/Jozsef_Hegedus)\
**Post date:** [January 31, 2019, 5:09pm UTC](https://discourse.mc-stan.org/t/model-header-hpp25-fatal-error-stan-math-hpp-no-such-file-or-directory/7538/4 "2019-01-31T17:09:25Z")

</div>

So, @bgoodri

I should install the latest RStan from source ?  
You mean this command ?

```
install.packages("rstan", type = "source")

```

from here : [https://github.com/stan-dev/rstan/wiki/Installing-RStan-on-Linux](https://github.com/stan-dev/rstan/wiki/Installing-RStan-on-Linux) ?

Is that what you mean by latest ?

Cheers

Jozsef

---

<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:** [January 31, 2019, 6:36pm UTC](https://discourse.mc-stan.org/t/model-header-hpp25-fatal-error-stan-math-hpp-no-such-file-or-directory/7538/5 "2019-01-31T18:36:31Z")

</div>

Yes, although on Linux `type = "source"` is the default.

---

<div class="post-metadata">

**Author:** ![Jozsef\_Hegedus](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jozsef_hegedus/32/3825_2.png) [@Jozsef\_Hegedus](https://discourse.mc-stan.org/u/Jozsef_Hegedus)\
**Post date:** [February 2, 2019, 6:56am UTC](https://discourse.mc-stan.org/t/model-header-hpp25-fatal-error-stan-math-hpp-no-such-file-or-directory/7538/6 "2019-02-02T06:56:14Z")

</div>

Hi @bgoodri,

I got this result :

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/6/6d4781dae7de9e5ea57d4aa3baf14456f8752c22.png)  
with the following Makevars :  
 ![image](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/b/b21acb681273821a0f8cab1d65b3b5a057252d46.png)

is there some simple easy one line command that tests that `rstan` was correctly installed  
and can compile and run HMC simulations ? Or do I have to run my own program to do that ?

Or is it possible to write a simple one line Stan code that prints "hello world ?  
EDIT : I found this - perfect !  
[https://mc-stan.org/workshops/halifax2017/exercise\_2.html](https://mc-stan.org/workshops/halifax2017/exercise_2.html)

Cheers,

Jozsef

---

<div class="post-metadata">

**Author:** ![Jozsef\_Hegedus](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jozsef_hegedus/32/3825_2.png) [@Jozsef\_Hegedus](https://discourse.mc-stan.org/u/Jozsef_Hegedus)\
**Post date:** [February 4, 2019, 8:56am UTC](https://discourse.mc-stan.org/t/model-header-hpp25-fatal-error-stan-math-hpp-no-such-file-or-directory/7538/7 "2019-02-04T08:56:09Z")

</div>

Got it working ! Thanks @bgoodri ! J.
