Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to use Eigen in a C++ program?

I read the documentation of Eigen installation. As per the documentation, only header files need to be referred in your project. As shown in the screenshot below, I included the path of the Eigen in my include directories, but the program does not recognize Eigen.

enter image description here

Sample Code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

#include <iostream>
#include <Eigen/Dense>

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);
    std::cout << m << std::endl;
}

How do I correctly include the Eigen into my C++ project?

>Solution :

You added path/to/eigen-3.4.0/Eigen to your include path, but then you include the header Eigen/Dense, so this looks for path/to/eigen-3.4.0/Eigen/Eigen/Dense. That’s one Eigen too many.

Set the include path to path/to/eigen-3.4.0 instead.

(Don’t be tempted to modify the include to #include <Dense> instead. It might cause Eigen to be unable to find its own headers, and can also easily lead to naming conflicts.)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading