Fail to compile template lib (Eigen)

Eigen is a template library, just a bunch of header files which produce some nicely optimized inline code. The library compiles when it’s in a VS project, but trying to include it in UE4 gives me a bunch of errors.

I don’t think I can create a module out of Eigen, because it’s not a regular library, just header files.

Here’s the relevant part of my error log

[2016.06.23-03.34.39:141][373]CompilerResultsLog: Info Performing 7 actions (4 in parallel)
[2016.06.23-03.34.39:141][373]CompilerResultsLog: Info PCH.test_2.h.cpp
[2016.06.23-03.34.39:141][373]CompilerResultsLog:Error: Error C:\Users\\Documents\Unreal Projects\test_2\Source\test_2\Public\Eigen\src\Core\Array.h(35) : error C2988: unrecognizable template declaration/definition
[2016.06.23-03.34.39:141][373]CompilerResultsLog:Error: Error C:\Users\\Documents\Unreal Projects\test_2\Source\test_2\Public\Eigen\src\Core\Array.h(35) : error C2143: syntax error: missing ';' before '<'
[2016.06.23-03.34.39:141][373]CompilerResultsLog:Error: Error C:\Users\\Documents\Unreal Projects\test_2\Source\test_2\Public\Eigen\src\Core\Array.h(35) : error C2059: syntax error: '<'
[2016.06.23-03.34.39:141][373]CompilerResultsLog:Error: Error C:\Users\\Documents\Unreal Projects\test_2\Source\test_2\Public\Eigen\src\Core\Array.h(35) : error C2065: 'Matrix': undeclared identifier
[2016.06.23-03.34.39:141][373]CompilerResultsLog:Error: Error C:\Users\\Documents\Unreal Projects\test_2\Source\test_2\Public\Eigen\src\Core\Array.h(35) : error C2065: '_Scalar': undeclared identifier
[2016.06.23-03.34.39:141][373]CompilerResultsLog:Error: Error C:\Users\\Documents\Unreal Projects\test_2\Source\test_2\Public\Eigen\src\Core\Array.h(35) : error C2065: '_Rows': undeclared identifier
[2016.06.23-03.34.39:141][373]CompilerResultsLog:Error: Error C:\Users\\Documents\Unreal Projects\test_2\Source\test_2\Public\Eigen\src\Core\Array.h(35) : error C2065: '_Cols': undeclared identifier
[2016.06.23-03.34.39:141][373]CompilerResultsLog:Error: Error C:\Users\\Documents\Unreal Projects\test_2\Source\test_2\Public\Eigen\src\Core\Array.h(35) : error C2065: '_Options': undeclared identifier
[2016.06.23-03.34.39:141][373]CompilerResultsLog:Error: Error C:\Users\\Documents\Unreal Projects\test_2\Source\test_2\Public\Eigen\src\Core\Array.h(35) : error C2065: '_MaxRows': undeclared identifier
[2016.06.23-03.34.39:141][373]CompilerResultsLog:Error: Error C:\Users\\Documents\Unreal Projects\test_2\Source\test_2\Public\Eigen\src\Core\Array.h(35) : error C2065: '_MaxCols': undeclared identifier
[2016.06.23-03.34.39:141][373]CompilerResultsLog:Error: Error C:\Users\\Documents\Unreal Projects\test_2\Source\test_2\Public\Eigen\src\Core\Array.h(35) : error C2974: 'Eigen::internal::traits': invalid template argument for '_Scalar', type expected
[2016.06.23-03.34.39:141][373]CompilerResultsLog:Error: Error C:\Users\\Documents\Unreal Projects\test_2\Source\test_2\Public\Eigen\src\Core\Array.h(35) : note: see declaration of 'Eigen::internal::traits'
[2016.06.23-03.34.39:141][373]CompilerResultsLog:Error: Error C:\Users\\Documents\Unreal Projects\test_2\Source\test_2\Public\Eigen\src\Core\Array.h(35) : error C2975: '_Rows': invalid template argument for 'Eigen::internal::traits', expected compile-time constant expression
[2016.06.23-03.34.39:141][373]CompilerResultsLog:Error: Error C:\Users\\Documents\Unreal Projects\test_2\Source\test_2\Public\Eigen\src\Core\Array.h(34) : note: see declaration of '_Rows'
[2016.06.23-03.34.39:141][373]CompilerResultsLog:Error: Error C:\Users\\Documents\Unreal Projects\test_2\Source\test_2\Public\Eigen\src\Core\Array.h(35) : error C2975: '_Cols': invalid template argument for 'Eigen::internal::traits', expected compile-time constant expression
[2016.06.23-03.34.39:141][373]CompilerResultsLog:Error: Error C:\Users\\Documents\Unreal Projects\test_2\Source\test_2\Public\Eigen\src\Core\Array.h(34) : note: see declaration of '_Cols'
[2016.06.23-03.34.39:141][373]CompilerResultsLog:Error: Error C:\Users\\Documents\Unreal Projects\test_2\Source\test_2\Public\Eigen\src\Core\Array.h(35) : error C2975: '_Options': invalid template argument for 'Eigen::internal::traits', expected compile-time constant expression
[2016.06.23-03.34.39:141][373]CompilerResultsLog:Error: Error C:\Users\\Documents\Unreal Projects\test_2\Source\test_2\Public\Eigen\src\Core\Array.h(34) : note: see declaration of '_Options'
[2016.06.23-03.34.39:141][373]CompilerResultsLog:Error: Error C:\Users\\Documents\Unreal Projects\test_2\Source\test_2\Public\Eigen\src\Core\Array.h(35) : error C2975: '_MaxRows': invalid template argument for 'Eigen::internal::traits', expected compile-time constant expression
[2016.06.23-03.34.39:141][373]CompilerResultsLog:Error: Error C:\Users\\Documents\Unreal Projects\test_2\Source\test_2\Public\Eigen\src\Core\Array.h(34) : note: see declaration of '_MaxRows'
[2016.06.23-03.34.39:141][373]CompilerResultsLog:Error: Error C:\Users\\Documents\Unreal Projects\test_2\Source\test_2\Public\Eigen\src\Core\Array.h(35) : error C2975: '_MaxCols': invalid template argument for 'Eigen::internal::traits', expected compile-time constant expression
[2016.06.23-03.34.39:141][373]CompilerResultsLog:Error: Error C:\Users\\Documents\Unreal Projects\test_2\Source\test_2\Public\Eigen\src\Core\Array.h(34) : note: see declaration of '_MaxCols'
[2016.06.23-03.34.39:141][373]CompilerResultsLog:Error: Error C:\Users\\Documents\Unreal Projects\test_2\Source\test_2\Public\Eigen\src\Core\Array.h(35) : error C2143: syntax error: missing ';' before '>'
[2016.06.23-03.34.39:141][373]CompilerResultsLog:Error: Error C:\Users\\Documents\Unreal Projects\test_2\Source\test_2\Public\Eigen\src\Core\Array.h(35) : error C2059: syntax error: '>'

This isn’t all the errors by the way, just the first few

What version of Eigen are you using? Line 35 of /Core/Array.h in the latest release (3.2) doesn’t look like it would throw that kind of error. https://bitbucket.org/eigen/eigen/src/7fde62a57495f7165ac43aa509d9d83edea1fd50/Eigen/src/Core/Array.h?at=default&fileviewer=file-view-default

The same version, but accidentally added a couple lines of whitespace. Someone else was having macro conflicts, so I was trying to #undef a bunch of things.

The first error is on this line 33 (35 for me), I can regenerate the error log if it would make it any easier

template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>

Also:
I still get the same set of errors when I remove the #include

Maybe the headers are trying to be compiled into a compilation unit or something, because they are in the Public directory. Prior to me placing Eigen there I couldn’t even get the compiler to see the lib

Could you post the Eigen::internal::traits declaration? i.e. lines 30-40?

namespace internal {
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
struct traits<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > : traits<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
{
typedef ArrayXpr XprKind;
typedef ArrayBase<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > XprBase;
};
}

Not an elegant solution, but I fixed it by placing the Eigen headers in the Source/proj directory and calling

#include "Eigen"

instead of the proper way

PrivateIncludePaths.Add(".....Unreal Projects/proj/Source/proj/Eigen");
#include <Eigen>

Thanks! this was driving me mad.

Thank you, needed the same stuff and it is working now!

Hi, I also want to use Eigen and I’m having the same problem even after adding all the files (folder structure) to VS2015. Can you please detail how you made it work? Your folder structure, your includes. Did you add anything in Project>Properties>VC++ Directories ? Please detail.