Model_header.hpp:4:25: fatal error: stan/math.hpp: No such file or directory

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,

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'))"`

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

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


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")

If you are reporting a bug (thank you!) please use the issue tracker ( instead of the forums.

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

Hi @bgoodri,

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



So, @bgoodri

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

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

from here : ?

Is that what you mean by latest ?



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

1 Like

Hi @bgoodri,

I got this result :

with the following Makevars :

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 !



Got it working ! Thanks @bgoodri ! J.