Problems using translated stan model in C++

I have implemented a complex model in Stan. I translated it using CMDSTAN(stanc) as explained here: https://mc-stan.org/docs/2_28/cmdstan-guide-2_28.pdf

When I included the generated .hpp into my C++ code, I got compilation errors like the following:

I tried to solve the include paths errors, but the errors regarding stan::promote_args_t and local_scalar_t I don’t know how to fix it.

Is this a problem with some missing stan header files or something else?

  • Operating System: MacOS Mojave 10.14.6
  • CmdStan Version: 2.28.1
  • Compiler/Toolkit: Xcode, C++17

Eigen 3.4

Hi,

so to understand this correctly, are you trying to use this with existing C++ code or just to run a model and use the samples?

yes, I have an existing C++ code that "produces "(some algorithm) the input data for the stan model. Then I translated the stan model using CMDSTAN, in order to run the model from C++.

So the C++ is only used to generate the input data? If I am understanding that correctly, then I would propose writing that data out to a JSON file and using Stan via the interface, not tightly coupling via C++.

If you need to interact via C++ then I would suggest just using the core Stan library (github.com/stan-dev/stan) without the CmdStan interface, as the interface is intended for the command line.

1 Like

I managed to solve the initial compilation errors. Then I got a different ones:
-With the -D_REENTRANT
Following the advice from this link:

https://github.com/stan-dev/cmdstan/issues/770

I added -D_REENTRANT to the CMAKE_CXX_FLAGS in cmake and now I got another compilation problems with stan_math:

No member named 'adj' in 'Eigen::Map<Eigen::Matrix<stan::math::vari_value<double, void> *, -1, -1, 0, -1, -1>, 0, Eigen::Stride<0, 0> >'

Can anyone from the Stan team can help with this, @rok_cesnovar ?