Hi everyone!
I am trying to understand how to develop an external function for the CmdStan interface using a C++ code.
The version I have is 2.25, I added in the make/local CXXFLAGS_PROGRAM += -include $(USER_HEADER) but I did not solve the problem yet.
I followed the tutorial in the manual and I reproduced the same example.
functions{
real make_odds (real theta);
}
data{
int<lower=0> N;
int<lower=0,upper=1> y[N];
}
parameters{
real<lower=0,upper=1> theta;
}
model{
theta~beta(1,1);
y~bernoulli(theta);
}
generated quantities{
real odds;
odds=make_odds(theta);
}
namespace bernoulli_model_namespace{
template <typename T0__> inline typename boost::math::tools::promote_args<T0__>::type make_odds(const T0__& theta, std::ostream* pstream__){
return theta/(1-theta);
}
}
The error I get when I run
STANCFLAGS=--allow-undefined USER_HEADER=examples/external-function/make_odds.hpp make examples/external-function/bernoulli
is the following:
--- Compiling, linking C++ code ---
g++ -std=c++1y -pthread -D_REENTRANT -Wno-sign-compare -Wno-ignored-attributes -I stan/lib/stan_math/lib/tbb_2019_U8/include -O3 -I src -I stan/src -I lib/rapidjson_1.1.0/ -I lib/CLI11-1.9.1/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.3.9 -I stan/lib/stan_math/lib/boost_1.72.0 -I stan/lib/stan_math/lib/sundials_5.6.1/include -I/home/fbrarda/cmdstan-petsc/stan/lib/stan_math/lib/boost_1.72.0 -DBOOST_DISABLE_ASSERTS -c -include examples/external-function/make_odds.hpp -Wno-ignored-attributes -include examples/external-function/make_odds.hpp -x c++ -o examples/external-function/bernoulli.o examples/external-function/bernoulli.hpp
In file included from <command-line>:0:0:
./examples/external-function/make_odds.hpp:3:42: error: ‘boost’ has not been declared
template <typename T0__> inline typename boost::math::tools::promote_args<T0__>::type make_odds(const T0__& theta, std::ostream* pstream__){
^
./examples/external-function/make_odds.hpp:3:74: error: expected unqualified-id before ‘<’ token
template <typename T0__> inline typename boost::math::tools::promote_args<T0__>::type make_odds(const T0__& theta, std::ostream* pstream__){
^
In file included from <command-line>:0:0:
./examples/external-function/make_odds.hpp:3:42: error: ‘boost’ has not been declared
template <typename T0__> inline typename boost::math::tools::promote_args<T0__>::type make_odds(const T0__& theta, std::ostream* pstream__){
^
./examples/external-function/make_odds.hpp:3:74: error: expected unqualified-id before ‘<’ token
template <typename T0__> inline typename boost::math::tools::promote_args<T0__>::type make_odds(const T0__& theta, std::ostream* pstream__){
^
I do not understand why I get this error and neither why the boost library is included twice (also from another directory - cmdstan-petsc which uses the 2.24 version of CmdStan).
I very much appreciate any help to understand where I am wrong.
Francesco