Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
119 user(s) are online (110 user(s) are browsing Forums)

Members: 1
Guests: 118

K-L, more...

Support us!

Headlines

 
  Register To Post  

gcc8.2.0 issues with std: stoi, stol, stod, etc. How to fix ?
Home away from home
Home away from home


See User information
Most of us when port something with recent gcc, offten meet with issues when one or another function bring errors like "error: ‘func()’ is not a member of ‘std’".

Lately found that not only stoi(), but also stod(), stof(), stoul() and stol() can't be used as "not a members of std".

Doing some search, i found few files like this:

include\c++\8.2.0\bits\basic_string.h
include\c++\8.2.0\ext\vstring.h

Where we can see something like this (copy from vstring.h):

namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION

#if _GLIBCXX_USE_C99_STDLIB
  // 21.4 Numeric Conversions [string.conversions].
  
inline int
  stoi
(const __vstring__strstd::size_t__idx 0int __base 10)
  { return 
__gnu_cxx::__stoa<longint>(&std::strtol"stoi"__str.c_str(),
                    
__idx__base); }

  
inline long
  stol
(const __vstring__strstd::size_t__idx 0int __base 10)
  { return 
__gnu_cxx::__stoa(&std::strtol"stol"__str.c_str(),
                 
__idx__base); }

  
inline unsigned long
  stoul
(const __vstring__strstd::size_t__idx 0int __base 10)
  { return 
__gnu_cxx::__stoa(&std::strtoul"stoul"__str.c_str(),
                 
__idx__base); }

  
inline long long
  stoll
(const __vstring__strstd::size_t__idx 0,    int __base 10)
  { return 
__gnu_cxx::__stoa(&std::strtoll"stoll"__str.c_str(),
                 
__idx__base); }

  
inline unsigned long long
  stoull
(const __vstring__strstd::size_t__idxint __base 10)
  { return 
__gnu_cxx::__stoa(&std::strtoull"stoull"__str.c_str(),
                 
__idx__base); }

  
// NB: strtof vs strtod.
  
inline float
  stof
(const __vstring__strstd::size_t__idx 0)
  { return 
__gnu_cxx::__stoa(&std::strtof"stof"__str.c_str(), __idx); }

  
inline double
  stod
(const __vstring__strstd::size_t__idx 0)
  { return 
__gnu_cxx::__stoa(&std::strtod"stod"__str.c_str(), __idx); }

  
inline long double
  stold
(const __vstring__strstd::size_t__idx 0)
  { return 
__gnu_cxx::__stoa(&std::strtold"stold"__str.c_str(), __idx); }
#endif // _GLIBCXX_USE_C99_STDLIB



So, by logic enabling of _GLIBCXX_USE_C99_STDLIB should did the trick and they should work, but sadly just adding

#define _GLIBCXX_USE_C99_STDLIB 1

to include/c++/8.2.0/bits/c++config.h do not help.

It all just looks like it all can and should works, just in our GCC something not enabled or so..

Or maybe someone have some easy typedef which can be used instead ? Like something of that sort:

#ifdef __amigaos4__
namespace std 

typedef stoi ....;
typedef stod ....;
typedef stof ....;
typedef stol ....;
typedef stoul ....;

}
#endif


Any ideas and help apprecated, thanks!

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: gcc8.2.0 issues with std: stoi, stol, stod, etc. How to fix ?
Home away from home
Home away from home


See User information
@All
At moment found solution myself, a bit not clean as it , but still, maybe someone will have needs for:

To make those functions works without any code changes, you can add "-D_GLIBCXX_USE_C99_STDLIB" to makefile when compile objects, as well, as on linking stage you will have needs to add -lstdc++ too.

For example that test case:

#include <cstdio>

#include <thread>
#include <future>

#include <cstdio>
#include <unistd.h>


enum MapParameterIndices int
{
    
LEVELPARAM_CHANCE_SECRET,
    
LEVELPARAM_CHANCE_DARKNESS,
    
LEVELPARAM_CHANCE_MINOTAUR
};

std::string parameterStr "";

std::tuple<intintintmapParameters std::make_tuple(-1, -1, -1);



int main()
{

    
std::get<LEVELPARAM_CHANCE_SECRET>(mapParameters) = std::stoi(parameterStr);
}


Didn't work when we just do "ppc-amigaos-gcc test.cpp", and bring usual " error: ‘stoi’ is not a member of ‘std’", but then, if we do:

ppc-amigaos-gcc -D_GLIBCXX_USE_C99_STDLIB test.cpp , then object compiles fine, just linking fail, which we fix by adding -lstdc++ (together with our -athread=native and -lpthread).

So to summorize to compile that test case and make it works we do:

ppc-amigaos-gcc -D_GLIBCXX_USE_C99_STDLIB test.cpp -athread=native -lpthread -lstdc++

Of course we can use #define _GLIBCXX_USE_C99_STDLIB 1 in source code as well, or (by logic) in that c++config.h in our includes, but that sometime may not work, as seems some other includes also redefine it somehow.

That at least help with functions i check: stoi, stol, stod, stoul & stof. All compiles and links fine without code changes.

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: gcc8.2.0 issues with std: stoi, stol, stod, etc. How to fix ?
Home away from home
Home away from home


See User information
@kas1e

Those functions should be available with -std=c++11 (or higher).

Hans

Join Kea Campus' Amiga Corner and support Amiga content creation
https://keasigmadelta.com/ - see more of my work
Go to top
Re: gcc8.2.0 issues with std: stoi, stol, stod, etc. How to fix ?
Home away from home
Home away from home


See User information
@Hans
Yeah, they should, same as to_string(), basic_string(), etc. But as we all found , it is not.

So it can be some misconfiguration or misdefines of our latest gcc.

Remember that you have yourself the same problem, just with to_string() not being member of std :

https://github.com/sba1/adtools/issues/58

And that one you fix by enabling _GLIBCXX_USE_C99_STDIO. While those ones with stoi and co, fixed by adding by enabling _GLIBCXX_USE_C99_STDLIB.

In all cases , not c++11, not gnu++11 or whatever else didn't work. And i am somehow sure it is something in gcc configured wrong.

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: gcc8.2.0 issues with std: stoi, stol, stod, etc. How to fix ?
Home away from home
Home away from home


See User information
@kas1e

Ah yes, that's a mistake in the newlib headers. IIRC, it works correctly if you use clib2.

Hans

Join Kea Campus' Amiga Corner and support Amiga content creation
https://keasigmadelta.com/ - see more of my work
Go to top
Re: gcc8.2.0 issues with std: stoi, stol, stod, etc. How to fix ?
Home away from home
Home away from home


See User information
@Hans
If use clib2, then your issue about to_string() is gone, yes, but with stoi() and co, issue still here even with clib2.

My bet is not only newlib headers guilty (maybe with case of to_string() only newlib ), but also pure gcc includes as well (that c++config.h file, etc).

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project