Eigen 3.3 对 mingw-w64 (GCC 7.1.0) 有很多警告

Eigen 3.3 has many warnings with mingw-w64 (GCC 7.1.0)

从mingw-w64 GCC 6.2更新到GCC 7.1(准确的说是migw-w64版本x86_64-7.1.0-posix-sjlj-rt_v5-rev0)后,编译器出现大量警告。例如:

In file included from C:\...\Eigen3_3_3/Eigen/Eigenvalues:45:0,
                 from C:\...\Eigen3_3_3/Eigen/Dense:7,
                 from ..\src\testProject.cpp:5:
C:\...\Eigen3_3_3/Eigen/src/Eigenvalues/GeneralizedEigenSolver.h:292:14: warning: optimization attribute on 'int abs(int)' follows definition but the attribute doesn't match [-Wattributes]
   using std::abs;
              ^~~
In file included from C:/.../mingw-w64/x86_64-7.1.0-posix-sjlj-rt_v5-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/7.1.0/include/c++/cmath:47:0,
                 from C:/.../mingw-w64/x86_64-7.1.0-posix-sjlj-rt_v5-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/7.1.0/include/c++/complex:44,
                 from C:\...\Eigen\Eigen3_3_3/Eigen/Core:80,
                 from C:\...\Eigen\Eigen3_3_3/Eigen/Dense:1,
                 from ..\src\testProject.cpp:5:
C:/.../mingw-w64/x86_64-7.1.0-posix-sjlj-rt_v5-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/7.1.0/include/c++/bits/std_abs.h:84:3: note: previous definition of 'constexpr __int128 std::abs(__int128)' was here
   abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
   ^~~

这是编译器的问题还是我应该向 Eigen 开发人员报告错误?

这是由于 gcc-7 中的一个错误: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89325

我只是推出了解决方法(即屏蔽警告): http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1724(将成为 Eigen 3.3.8 的一部分)。

如果您无法从存储库(或默认分支)升级到 3.3 版本,或者等待 3.3.8,您可以将 -Wno-attributes 添加到您的编译标志中。