I have the following test program using eigen:
#include <iostream>
#include <Eigen/Dense>
using namespace std;
using Eigen::MatrixXd;
int main() {
MatrixXd m(2, 2);
m(0, 0) = 3;
m(1, 0) = 2.5;
m(0, 1) = -1;
m(1, 1) = m(1, 0) + m(0, 1);
cout << m << endl;
}
and I can compile it with g++ -I/usr/include/eigen3/ test1.cpp
.
However, the compile command doesn't work if I don't specify the include flag. This seems strange to me because I thought that any headers under /usr/include
will be picked up automatically by the compiler (e.g. Boost headers, also located under /usr/include
, work perfectly fine without having to tell the compiler where to look for them). What changes do I need to make to the eigen setup so I don't have to specify the -I flag in the compile command?
If you replace
#include <Eigen/Dense>
by
#include <eigen3/Eigen/Dense>
your code will compile. In other words, the problem is that you are including <Eigen/Dense>
which is in the directory /usr/include/eigen3
, but the compiler only searches in /usr/include
by default.
I would recommend using include flags, instead of including <eigen3/Eigen/Dense>
, because this is more portable across distributions, operating systems, etc. and generally, it is easier to configure compilation for other environments. Eigen3 comes with pkg-config files, which are very easy to use and portable. Compiling with
g++ $(pkg-config --cflags eigen3) test1.cpp
will work on all platforms, where pkg-config is available and it is a great alternative for you, if you want to avoid the hard-coded include paths.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With