“数字限制”不是“std”的成员;
我正在尝试从源代码 FlyWithLua 编译一个应用程序,其中包括 sol2 库。
我正在按照说明进行操作,但是当我运行 cmake --build ./build
时,我收到以下错误:
In file included from /home/jon/src/FlyWithLua/src/FloatingWindows
/FLWIntegration.cpp:10:
/home/jon/src/FlyWithLua/src/third_party/sol2/./upstream/sol.hpp: In lambda function:
/home/jon/src/FlyWithLua/src/third_party/sol2/./upstream/sol.hpp:7194:59:
error: ‘numeric_limits’ is not a member of ‘std’
7194 | std::size_t space = (std::numeric_limits<std::size_t>::max)();
此后同一行上还有其他几个错误,但我猜它们可能会消失,如果我可以解决这个问题。
将以下包含内容添加到 .hpp 的解决方案存在几个类似问题 sol.hpp
文件
#include <stdexcept>
#include <limits>
包含以下导入:
#include <stddef.h>
#include <limits.h>
https://sol2.readthedocs.io/en/latest/errors.html 给出了一些有关编译器可能无法识别这些内容的提示:
编译器错误/警告
当出现问题时,可能会出现无数的编译器错误。这里 关于使用这些类型的一些基本建议:
如果存在大量与 std::index_sequence、类型特征相关的错误, 和其他 std:: 成员,很可能您还没有打开 C++14 开关 你的编译器。 Visual Studio 2015 默认情况下打开这些,但 g++ 和 clang++ 没有将它们作为默认值,您应该传递标志 --std=c++1y 或 --std=c++14,或类似的编译器。
src/CMakeList.txt 文件具有以下行:
设置(CMAKE_CXX_STANDARD 17)
我对 C/C++ 只是有点熟悉,这对我来说似乎非常复杂,但我希望对于更熟练的人来说可能有一个容易识别的原因和解决方案。
cat /etc/*-release
给出
DISTRIB_RELEASE=21.10
DISTRIB_CODENAME=impish
DISTRIB_DESCRIPTION="Ubuntu 21.10"
$ g++ --version
g++ (Ubuntu 11.2.0-7ubuntu2) 11.2.0
I am trying to compile an application from source, FlyWithLua, which includes the sol2 library.
I am following the instructions but when I run cmake --build ./build
I get the following error:
In file included from /home/jon/src/FlyWithLua/src/FloatingWindows
/FLWIntegration.cpp:10:
/home/jon/src/FlyWithLua/src/third_party/sol2/./upstream/sol.hpp: In lambda function:
/home/jon/src/FlyWithLua/src/third_party/sol2/./upstream/sol.hpp:7194:59:
error: ‘numeric_limits’ is not a member of ‘std’
7194 | std::size_t space = (std::numeric_limits<std::size_t>::max)();
There are several other errors on the same line after this, but I guess they might just go away if I can solve this one.
there are several similar issues with the solution to add the following includes to the .hpp file
#include <stdexcept>
#include <limits>
the sol.hpp
file includes the following imports:
#include <stddef.h>
#include <limits.h>
https://sol2.readthedocs.io/en/latest/errors.html gives some hints about the why the compiler might not recognize these includes:
Compiler Errors / Warnings
A myriad of compiler errors can occur when something goes wrong. Here
is some basic advice about working with these types:If there are a myriad of errors relating to std::index_sequence, type traits, and other std:: members, it is likely you have not turned on your C++14 switch for your compiler. Visual Studio 2015 turns these on by default, but g++ and clang++ do not have them as defaults and you should pass the flag --std=c++1y or --std=c++14, or similar for your compiler.
the src/CMakeList.txt file has the following line:
set(CMAKE_CXX_STANDARD 17)
I'm only faintly familiar with C/C++ and this all seems very complicated to me, but I'm hoping that there might be an easily recognizable cause and solution to this to someone more skilled.
cat /etc/*-release
gives
DISTRIB_RELEASE=21.10
DISTRIB_CODENAME=impish
DISTRIB_DESCRIPTION="Ubuntu 21.10"
$ g++ --version
g++ (Ubuntu 11.2.0-7ubuntu2) 11.2.0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我只需在使用此语句的错误所在的相应文件中包含
limits
而不是limits.h
即可消除此错误。I was able to remove this error by just including
limits
and notlimits.h
in the respective file where the error is using this statement.此错误消息暗示
src/third_party/sol2/./upstream/sol.hpp
标头使用std::numeric_limits
,而且还使用std::numeric_limits< /code> 尚未定义。最简单的解释是定义
std::numeric_limits
的标头尚未包含在内。在这种情况下,解决方案是包含定义std::numeric_limits
的标头。这证实了该问题。这些标头都没有定义 std::numeric_limits 。
这些提示可能适用于其他一些情况,但不适用于这种情况。
std::numeric_limits
从一开始就是 C++ 标准的一部分,因此语言版本对其存在没有影响。结论:根据引用的错误消息,sol.hpp 使用在标头
中定义的std::numeric_limits
,但根据您的说法,它没有t 包含该标头。如果是这种情况,那么这是 sol.hpp 文件中的错误。正确的解决方案是在使用std::numeric_limits
之前在该文件中包含
来修复 sol.hpp 文件。This error message implies that
src/third_party/sol2/./upstream/sol.hpp
header usesstd::numeric_limits
, but also thatstd::numeric_limits
hasn't been defined. The simplest explanation for that is that the header that definesstd::numeric_limits
hasn't been included. In such case, the solution is to include the header that definesstd::numeric_limits
.This confirms the problem. Neither of those headers define
std::numeric_limits
.Those hints may apply to some other cases, but not this one.
std::numeric_limits
has been part of the C++ standard since the beginning, so language version has no effect on its existence.Conclusion: According to the quoted error message, sol.hpp uses
std::numeric_limits
which is defined in the header<limits>
, but according to you, it doesn't include that header. If this is the case, then this is a bug in the sol.hpp file. Correct solution would be to fix the sol.hpp file by including<limits>
in that file before usingstd::numeric_limits
.