在新的Visual Studio项目中包含任何Eigen 3.3.1文件将无法编译

include of any Eigen 3.3.1 files in fresh Visual Studio project won't compile

本文关键字:文件 编译 Eigen Visual Studio 项目 包含任      更新时间:2023-10-16

我在VS2015中创建了一个新鲜的C (空)项目,然后将eigen 3.3.1源代码放在解决方案dir中的'inc'文件夹中,因此矩阵的路径。例如,H是 inc/eigen/core/。我已经将此 inc/路径设置为附加目录,并且还尝试使用 inc/eigen/em>作为另一个目录,以防这些文件彼此之间有包括彼此的问题,但这一切都没有改变。

在main.cpp中,我有以下内容:

#include "Eigen/Core/Matrix.h"
int main()
{
    return 0;
}

这给了我,当x64编译时:

1>c:usersbrodydocumentsvisual studio 2015projectseigentestinceigencorematrix.h(18): error C2988: unrecognizable template declaration/definition
1>c:usersbrodydocumentsvisual studio 2015projectseigentestinceigencorematrix.h(18): error C2143: syntax error: missing ';' before '<'
1>c:usersbrodydocumentsvisual studio 2015projectseigentestinceigencorematrix.h(18): error C2059: syntax error: '<'
1>c:usersbrodydocumentsvisual studio 2015projectseigentestinceigencorematrix.h(19): error C2143: syntax error: missing ';' before '{'
1>c:usersbrodydocumentsvisual studio 2015projectseigentestinceigencorematrix.h(19): error C2447: '{': missing function header (old-style formal list?)
1>c:usersbrodydocumentsvisual studio 2015projectseigentestinceigencorematrix.h(179): error C2143: syntax error: missing ',' before '<'
1>  c:usersbrodydocumentsvisual studio 2015projectseigentestinceigencorematrix.h(404): note: see reference to class template instantiation 'Eigen::Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols>' being compiled
1>c:usersbrodydocumentsvisual studio 2015projectseigentestinceigencorematrix.h(186): error C2143: syntax error: missing ';' before '<'
1>c:usersbrodydocumentsvisual studio 2015projectseigentestinceigencorematrix.h(186): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:usersbrodydocumentsvisual studio 2015projectseigentestinceigencorematrix.h(186): error C2238: unexpected token(s) preceding ';'
1>c:usersbrodydocumentsvisual studio 2015projectseigentestinceigencorematrix.h(192): error C2653: 'Base': is not a class or namespace name
1>c:usersbrodydocumentsvisual studio 2015projectseigentestinceigencorematrix.h(192): error C2144: syntax error: 'int' should be preceded by ';'
1>c:usersbrodydocumentsvisual studio 2015projectseigentestinceigencorematrix.h(192): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:usersbrodydocumentsvisual studio 2015projectseigentestinceigencorematrix.h(192): warning C4183: 'EIGEN_DENSE_PUBLIC_INTERFACE': missing return type; assumed to be a member function returning 'int'
1>c:usersbrodydocumentsvisual studio 2015projectseigentestinceigencorematrix.h(192): error C3646: 'PlainObject': unknown override specifier
1>c:usersbrodydocumentsvisual studio 2015projectseigentestinceigencorematrix.h(194): error C2653: 'Base': is not a class or namespace name
1>c:usersbrodydocumentsvisual studio 2015projectseigentestinceigencorematrix.h(195): error C2653: 'Base': is not a class or namespace name
1>c:usersbrodydocumentsvisual studio 2015projectseigentestinceigencorematrix.h(206): error C3646: 'EIGEN_STRONG_INLINE': unknown override specifier
1>c:usersbrodydocumentsvisual studio 2015projectseigentestinceigencorematrix.h(206): error C3646: 'Matrix': unknown override specifier
1>c:usersbrodydocumentsvisual studio 2015projectseigentestinceigencorematrix.h(206): error C2143: syntax error: missing ';' before '&'
1>c:usersbrodydocumentsvisual studio 2015projectseigentestinceigencorematrix.h(206): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:usersbrodydocumentsvisual studio 2015projectseigentestinceigencorematrix.h(207): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>c:usersbrodydocumentsvisual studio 2015projectseigentestinceigencorematrix.h(223): error C2061: syntax error: identifier 'EIGEN_STRONG_INLINE'
1>c:usersbrodydocumentsvisual studio 2015projectseigentestinceigencorematrix.h(237): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>c:usersbrodydocumentsvisual studio 2015projectseigentestinceigencorematrix.h(243): error C2061: syntax error: identifier 'EIGEN_STRONG_INLINE'
1>c:usersbrodydocumentsvisual studio 2015projectseigentestinceigencorematrix.h(259): error C2334: unexpected token(s) preceding ':'; skipping apparent function body
1>c:usersbrodydocumentsvisual studio 2015projectseigentestinceigencorematrix.h(14): fatal error C1075: the left brace '{' was unmatched at the end of the file

抱怨矩阵的第18行:

#ifndef EIGEN_MATRIX_H
#define EIGEN_MATRIX_H
namespace Eigen {
namespace internal {
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
struct traits<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > // line 18
{
private:
// etc...

任何其他特征#include都会出现类似的问题。我是否错过了一些必需的#include订购或一些编译标志或设置?谢谢!

您必须复制整个Eigen目录,而不仅仅是src子文件夹。而且,您不得直接包含src子文件夹中的文件,而必须在Eigen目录中包含文件。例如,#include <Eigen/Core>将包括所有核心功能,#include <Eigen/Dense>将包括所有密集功能(这包括核心,几何和分解)。