“numeric_limits”不是“std”的成员

CHs*_*fer 9 c++ lua xplane

我正在尝试从源代码FlyWithLua编译一个应用程序,其中包括 sol2 库。

\n

我按照说明进行操作,但是当我运行时cmake --build ./build出现以下错误:

\n
In file included from /home/jon/src/FlyWithLua/src/FloatingWindows\n\n/FLWIntegration.cpp:10:\n/home/jon/src/FlyWithLua/src/third_party/sol2/./upstream/sol.hpp: In lambda function:\n/home/jon/src/FlyWithLua/src/third_party/sol2/./upstream/sol.hpp:7194:59: \n      error: \xe2\x80\x98numeric_limits\xe2\x80\x99 is not a member of \xe2\x80\x98std\xe2\x80\x99\n7194 |               std::size_t space = (std::numeric_limits<std::size_t>::max)();\n
Run Code Online (Sandbox Code Playgroud)\n

此后同一行上还有其他几个错误,但我想如果我能解决这个错误,它们可能就会消失。

\n

将以下包含添加到 .hpp 文件的解决方案存在几个类似的问题

\n
#include <stdexcept>\n#include <limits>\n
Run Code Online (Sandbox Code Playgroud)\n

sol.hpp文件包含以下导入:

\n
#include <stddef.h>\n#include <limits.h>\n
Run Code Online (Sandbox Code Playgroud)\n

https://sol2.readthedocs.io/en/latest/errors.html给出了一些关于编译器可能无法识别这些内容的提示,包括:

\n
\n

编译器错误/警告

\n

当出现问题时,可能会出现无数的编译器错误。以下是有关使用这些类型的一些基本建议:

\n
If there are a myriad of errors relating to std::index_sequence, type traits, \nand other std:: members, it is likely you have not turned on your C++14 switch for\nyour compiler. Visual Studio 2015 turns these on by default, but g++ and clang++ \ndo not have them as defaults and you should pass the flag --std=c++1y or\n--std=c++14, or similar for your compiler.\n
Run Code Online (Sandbox Code Playgroud)\n
\n

src/CMakeList.txt 文件具有以下行:

\n
\n

设置(CMAKE_CXX_STANDARD 17)

\n
\n

我只是对 C/C++ 有点熟悉,这对我来说似乎非常复杂,但我希望对于更熟练的人来说可能有一个容易识别的原因和解决方案。

\n

cat /etc/*-release给出

\n
DISTRIB_RELEASE=21.10\nDISTRIB_CODENAME=impish\nDISTRIB_DESCRIPTION="Ubuntu 21.10"\n\n$ g++ --version\ng++ (Ubuntu 11.2.0-7ubuntu2) 11.2.0\n
Run Code Online (Sandbox Code Playgroud)\n

eer*_*ika 11

\n
/home/jon/src/FlyWithLua/src/third_party/sol2/./upstream/sol.hpp:7194:59:\n\n      error: \xe2\x80\x98numeric_limits\xe2\x80\x99 is not a member of \xe2\x80\x98std\xe2\x80\x99\n7194 |               std::size_t space = (std::numeric_limits<std::size_t>::max)();\n
Run Code Online (Sandbox Code Playgroud)\n
\n

此错误消息意味着src/third_party/sol2/./upstream/sol.hpp标头使用了std::numeric_limits,但还std::numeric_limits没有定义。最简单的解释是定义的标头std::numeric_limits尚未包含在内。在这种情况下,解决方案是包含定义std::numeric_limits.

\n
\n

sol.hpp 文件包含以下导入:

\n
#include <stddef.h>\n#include <limits.h>\n
Run Code Online (Sandbox Code Playgroud)\n
\n

这证实了问题。这些标头都没有定义std::numeric_limits.

\n
\n

https://sol2.readthedocs.io/en/latest/errors.html给出了一些关于编译器可能无法识别这些内容的提示,包括:

\n
\n

这些提示可能适用于其他一些情况,但不适用于本例。std::numeric_limits从一开始就是 C++ 标准的一部分,因此语言版本对其存在没有影响。

\n
\n

结论:根据引用的错误消息, sol.hpp 使用std::numeric_limitsheader 中定义的 which <limits>,但根据您的说法,它不包含该标头。如果是这种情况,那么这是 sol.hpp 文件中的错误。正确的解决方案是<limits>在使用 之前将 sol.hpp 文件包含在该文件中来修复该文件std::numeric_limits

\n


小智 11

我能够通过仅包含limits而不是包含limits.h在错误使用此语句的相应文件中来删除此错误。

#include <limits>
Run Code Online (Sandbox Code Playgroud)