0

我正在尝试从源代码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 文件的解决方案存在几个类似的问题

#include <stdexcept>
#include <limits>

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

#include <stddef.h>
#include <limits.h>

https://sol2.readthedocs.io/en/latest/errors.html提供了一些提示,说明编译器可能无法识别这些内容的原因包括:

编译器错误/警告

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

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.

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
4

1 回答 1

2
/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)();

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

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

#include <stddef.h>
#include <limits.h>

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

https://sol2.readthedocs.io/en/latest/errors.html提供了一些提示,说明编译器可能无法识别这些内容的原因包括:

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


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

于 2022-02-28T15:04:35.910 回答