Error: This compiler appears to be too old to be supported by Eigen

Error: This compiler appears to be too old to be supported by Eigen

我正在尝试编译一个包含 eigen 库的项目,但出现此错误:

In file included from /home/--/--/--/Eigen/Core:19,
             from /home/--/--/--/Eigen/Geometry:11,
             from /usr/include/rl-0.7.0/rl/math/Transform.h:34,
             from /home/--/--/--/example.cpp:2:
/home/--/--/--/Eigen/src/Core/util/Macros.h:674:2: error: #error This compiler appears to be too old to be supported by Eigen
674 | #error This compiler appears to be too old to be supported by Eigen
  |  ^~~~~

我正在使用:

问题似乎与 Macros.h 文件中的这些行有关:

// The macros EIGEN_HAS_CXX?? defines a rough estimate of available c++ features
// but in practice we should not rely on them but rather on the availability of
// individual features as defined later.
// This is why there is no EIGEN_HAS_CXX17.
#if EIGEN_MAX_CPP_VER<14 || EIGEN_COMP_CXXVER<14 || (EIGEN_COMP_MSVC && EIGEN_COMP_MSVC < 1900) || \
   (EIGEN_COMP_ICC && EIGEN_COMP_ICC < 1500) || (EIGEN_COMP_NVCC && EIGEN_COMP_NVCC < 80000) ||     \
   (EIGEN_COMP_CLANG && ((EIGEN_COMP_CLANG<309) || (defined(__apple_build_version__) && (__apple_build_version__ < 9000000)))) || \
   (EIGEN_COMP_GNUC_STRICT && EIGEN_COMP_GNUC<51)
#error This compiler appears to be too old to be supported by Eigen
#endif

你知道如何解决这个错误吗?

如您所述,Macros.h 文件告诉我们问题出在编译器版本上。

VSCode编译器

GCC 10 肯定支持 c++17。这意味着您应该更改它的起始标志。在 settings.json 文件中添加以下行:

"code-runner.executorMap": {
    "cpp": "cd $dir && g++ -std=c++17 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
},

根据

标准Bash的g++

使用带有 -std=c++17 标志的 g++。

正如@Lala5th 所建议的那样,通过更改 C++ 标准问题已解决。

我修改了 CMakeLists.txt:

发件人:

set(CMAKE_CXX_STANDARD 11)

收件人:

set(CMAKE_CXX_STANDARD 17)

(它也适用于 14)