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

If you are reporting a bug (thank you!) please use the issue tracker (github.com/stan-dev/rstan/issues) 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.

Cheers

Jozsef

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 ?

Is that what you mean by latest ?

Cheers

Jozsef

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

1 Like

Hi @bgoodri,

I got this result :


with the following Makevars :
image

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

Cheers,

Jozsef

Got it working ! Thanks @bgoodri ! J.