Home > Back-end >  ‘numeric_limits’ is not a member of ‘std’
‘numeric_limits’ is not a member of ‘std’

Time:03-01

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

CodePudding user response:

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

This error message implies that src/third_party/sol2/./upstream/sol.hpp header uses std::numeric_limits, but also that std::numeric_limits hasn't been defined. The simplest explanation for that is that the header that defines std::numeric_limits hasn't been included. In such case, the solution is to include the header that defines std::numeric_limits.

the sol.hpp file includes the following imports:

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

This confirms the problem. Neither of those headers define std::numeric_limits.

https://sol2.readthedocs.io/en/latest/errors.html gives some hints about the why the compiler might not recognize these includes:

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 using std::numeric_limits.

  • Related