Closed MessyShen closed 1 year ago
How about if you reorder the includes to
Also, Eigen/Dense
should already be included if you include stan/math.hpp
How about if you reorder the includes to
include <stan/math.hpp> #include <Eigen/Dense> // ! Compilation error if this line is added #include
Also,
Eigen/Dense
should already be included if you includestan/math.hpp
Thanks! By changing the order this example compiles correctly.
But I don't know why the order matters here and I still have this issue for a more complex program if I put #include<stan/math.hpp>
on top of some certain .hpp file.
I'll try to provide a minimal example for this ASAP.
It would be nice if you (or someone else) can explain this or fix the order issue.
Thanks again for replying ;-)
Stan-math uses Eigen plugins and is thereby a bit difficult wrt to header inclusion with Eigen. It's better to include first Stan-math (and then you anyway got Eigen included).
The reason is that Stan Math adds some things to the Eigen namespace https://github.com/stan-dev/math/blob/develop/stan/math/prim/fun/Eigen.hpp So that has to be included first no matter what.
The most general workaround for this, if you do not want to change the order of the includes, is to include that specific file I linked (stan/math/prim/fun/Eigen.hpp
) manually in the compile command with a -include ...
Thanks! It solves my problem! Thanks for your quick reply.
Description
When Eigen and Stan are included in the same file, g++ reports compilation errors like
‘const class stan::math::arena_matrix<Eigen::Matrix<stan::math::var_value<double>, -1, 1> >’ has no member named ‘val’; did you mean ‘eval’?
Example
I just add
#include <Eigen/Dense>
to the hello world program provided in the official installation guide.foo.cpp:
It's ok when I built the stan math library
but after running the following line:
I got errors like:
Expected Output
See the example above.
I'm building a program where there are some header files that does not rely on stan but must include eigen. If these header files are included, same error generates.
Current Version:
v4.5.0 gcc version 11.3.0 (Ubuntu 11.3.0-1ubuntu1~22.04)
Thanks!