Search code examples
c++visual-c++eigen

Linkage error - Eigen and Visual studio 2015


Dear C++ and Visual Studio developers,

I'm having a linkage problem with the Eigen library in Visual Studio 2015. Until now, I've followed all the solution purposes to link it, i.e. associated the necesssary folder to the external include of the project (Additional Include Directories ), without sucess. Despite of that, the library and the associated imports and namespaces keep not being recognized.

It would be helpful if one of you could give another possibility to solve it.

I thank you for the help and I'm looking forward for the answer.

Best regards.

PS.: As usual, sorry for the bad english. I'm not a native speaker.


Solution

  • Let's say you've downloaded the Eigen header files. In my case,

    D:\CPP_Libraries\Eigen_3.2.4
    

    Inside the aforementioned folder is

    enter image description here

    I will use command prompt for the sake of simplicity. Since Eigen library is a bunch of header files, we need to include the path. Now invoke the command prompt of visual studio and type

    cl /EHsc main.cpp /Fetest.exe /I D:\CPP_Libraries\Eigen_3.2.4
    

    For main.cpp,

    #include <iostream>
    #include <Eigen/Dense>
    
    int main()
    {
       //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
       Eigen::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 = \n"       << m       << std::endl << std::endl;
       std::cout << " m.inv() = \n" << m.inverse() << std::endl << std::endl;
       //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
       Eigen::MatrixXd b(3,3);
       b << 1, 2, 3,
            4, 5, 6,
            7, 8, 9;
        std::cout << " b = \n" << b  << std::endl << std::endl;
       //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
      return 0;
    }