我试图从源代码编译一个包括sol2库的应用程序,FlyWithLua。
我遵循说明进行操作,但当我运行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语句。
类似问题有很多,需要添加这些include语句。
#include <stdexcept>
#include <limits>
sol.hpp
文件中包含以下导入:
#include <stddef.h>
#include <limits.h>
https://sol2.readthedocs.io/en/latest/errors.html提供了一些关于编译器无法识别这些包含文件的原因的提示:
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.
src/CMakeList.txt文件包含以下行:
set(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
#include <limits>
?那应该可以解决问题。 - G.M.limits
和limits.h
是两个不同的头文件,你需要前者。limits.h
是 C 标准库的一个头文件。 - user17732522"I have #include <limits.h> but not #include <limits>"
:请按建议操作,加入#include <limits>
。limits.h
是C
语言头文件,不了解诸如std
的命名空间。 - G.M.#include <limits>
,编译成功了。谢谢! - CHsurfer