Including Eigen

2019-09-02 02:20发布

问题:

I've included the Eigen headers in a C++ project in Eclipse. When I try to build I get this error:

Symbol 'Eigen' could not be resolved    Semantic Error

From what I understand, this is a linker error, but Eigen is a header-only project and thus has no library to link against. The code that throws the error follows the basic tutorial they provide, and the offending snippet looks like this:

#include <Eigen/Dense>

using namespace Eigen;

What am I doing wrong? If it helps, I'm running this on Linux. Thanks.

回答1:

Eigen normally gets installed by most distributions to /usr/include/eigen2 and/or /usr/include/eigen3 or similar. Verify where the headers have been installed, as you need to add that path as an additional include path in your project.



回答2:

Check the compiler gets the correct include path. For example, the Eigen library headers may be installed in /usr/include/eigen3, so when compiling you'd have to give the compiler the flag -I /usr/include/eigen3.



回答3:

I was fiddling around and found that telling the Indexer to index unused headers resolved my problem.

Thanks for being on the ball guys. Kind of sorry I stumbled upon it myself.



回答4:

You should not put the headers directly in your project, it makes eclipse horribly slow and sometimes even shows warnings or even (wrong) errors. Instead, you should put the library somewher on disk and link to it (set the propper include directory) via project propperties -> c/c++ General -> GNU C++ -> Add -> File system -> Eigens root folder (where you extracted it to)