Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

psp-g++ error: ‘to_string’ is not a member of ‘std’ #108

Closed
GeoVa19 opened this issue Sep 17, 2019 · 23 comments
Closed

psp-g++ error: ‘to_string’ is not a member of ‘std’ #108

GeoVa19 opened this issue Sep 17, 2019 · 23 comments

Comments

@GeoVa19
Copy link

GeoVa19 commented Sep 17, 2019

Yet I'm compiling with either std=c++11 or std=c++14. There is an implementation of std::to_string under $PSPDEV/psp/include/c++/5.4.0/bits/basic_string.h, but all the code is under the preprocessor directive: #if __cplusplus >= 201103L && defined(_GLIBCXX_USE_C99). Any way to define _GLIBCXX_USE_C99 by default?

I'm using the version 5.4.0 from pull request #90.

In the past I also used the version this repository provides, and I had the same issue.

@davidgfnet
Copy link
Contributor

Could you test on gcc 8.3 at:
https://github.com/mrneo240/psptoolchain
and report back? I'm not sure what's causing this really ;)

@dbeef
Copy link
Member

dbeef commented Apr 17, 2020

Bundled GCC has been updated to 9.3.0. Could you re-install the toolchain and report whether your problem still exist?

@GeoVa19
Copy link
Author

GeoVa19 commented Apr 18, 2020

I wrote this sample code (replaced < and > with ", because GitHub hides what comes after it):

#include "iostream"
#include "string"

int main() {
auto a = 10;
std::string a_str = std::to_string(a);
return 0;
}

I compiled it with psp-g++ string.cpp -std=c++2a but still, same problem. The compiler says:

error: 'to_string' is not a member of 'std'; did you mean 'u32string'?

@dbeef
Copy link
Member

dbeef commented Apr 18, 2020

You can paste CPP code like this:

image

Which is rendered as:

int main()
{}

Anyways, I did some searching through GCC's basic_string.h, and it looks that to_string methods are visible only when underlying C library is GNU libc, here's to_string declaration:

#if _GLIBCXX_USE_C99_STDIO
  // NB: (v)snprintf vs sprintf.

  // DR 1261.
  inline string
  to_string(int __val)
  { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 4 * sizeof(int),
					   "%d", __val); }

  inline string
  to_string(unsigned __val)
  { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
					   4 * sizeof(unsigned),
					   "%u", __val); }

  inline string
  to_string(long __val)
  { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 4 * sizeof(long),
					   "%ld", __val); }

  inline string
  to_string(unsigned long __val)
  { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
					   4 * sizeof(unsigned long),
					   "%lu", __val); }

  inline string
  to_string(long long __val)
  { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
					   4 * sizeof(long long),
					   "%lld", __val); }

  inline string
  to_string(unsigned long long __val)
  { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
					   4 * sizeof(unsigned long long),
					   "%llu", __val); }

  inline string
  to_string(float __val)
  {
    const int __n = 
      __gnu_cxx::__numeric_traits<float>::__max_exponent10 + 20;
    return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
					   "%f", __val);
  }

  inline string
  to_string(double __val)
  {
    const int __n = 
      __gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20;
    return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
					   "%f", __val);
  }

  inline string
  to_string(long double __val)
  {
    const int __n = 
      __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 20;
    return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
					   "%Lf", __val);
  }
#endif // _GLIBCXX_USE_C99_STDIO

This could be solved on the psptoolchain side either by updating bundled newlib (although I am not sure of that) or by applying patch removing these guards in few places.
Relevant discussion:
https://gcc.gnu.org/legacy-ml/gcc-patches/2015-11/msg01808.html

Not closing this, as I'm going to actually try updating newlib soon.

@sharkwouter
Copy link
Member

sharkwouter commented May 9, 2020

Just to add to this, I ran into this just now with the latest toolchain.

@stefanmielke
Copy link

Also ran into this on diasurgical/devilutionX#1918. Had to change all to_string() calls to snprintf, but that also doesn't exist if using g++.

@carstene1ns
Copy link
Member

@stefanmielke: can you try using newlib from 3.3.0 branch? I never tested it thoroughly, but maybe is enough.

@stefanmielke
Copy link

@stefanmielke: can you try using newlib from 3.3.0 branch? I never tested it thoroughly, but maybe is enough.

@carstene1ns, should I just copy the includes, or rebuild the whole toolchain pointing to this branch?

@carstene1ns
Copy link
Member

Unfortunatly this involves rebuilding stage 2 gcc as well.
However, I doubt it will work. Might really need to patch gcc here.

@stefanmielke
Copy link

It seems to have worked, unfortunately had this side effect:

/usr/local/pspdev/psp/lib/libSDL.a(SDL_string.o): In function `SDL_strupr':
/home/stefanmielke/dev/psp/psptoolchain/build/psplibraries/build/SDL-1.2.15/./src/stdlib/SDL_string.c:385: undefined reference to `__ctype_ptr__'
/home/stefanmielke/dev/psp/psptoolchain/build/psplibraries/build/SDL-1.2.15/./src/stdlib/SDL_string.c:386: undefined reference to `__ctype_ptr__'
/usr/local/pspdev/psp/lib/libSDL.a(SDL_string.o): In function `SDL_strlwr':
/home/stefanmielke/dev/psp/psptoolchain/build/psplibraries/build/SDL-1.2.15/./src/stdlib/SDL_string.c:397: undefined reference to `__ctype_ptr__'
/home/stefanmielke/dev/psp/psptoolchain/build/psplibraries/build/SDL-1.2.15/./src/stdlib/SDL_string.c:398: undefined reference to `__ctype_ptr__'
/usr/local/pspdev/psp/lib/libSDL.a(SDL_string.o): In function `SDL_ScanUnsignedLong':
/home/stefanmielke/dev/psp/psptoolchain/build/psplibraries/build/SDL-1.2.15/./src/stdlib/SDL_string.c:83: undefined reference to `__ctype_ptr__'
/usr/local/pspdev/psp/lib/libSDL.a(SDL_string.o):/home/stefanmielke/dev/psp/psptoolchain/build/psplibraries/build/SDL-1.2.15/./src/stdlib/SDL_string.c:83: more undefined references to `__ctype_ptr__' follow

@carstene1ns
Copy link
Member

This is unfortunately a side-effect of updating the c library. :/
You will need to rebuild sdl as well.

@stefanmielke
Copy link

I changed the newlib stage and rebuilt the whole pipeline to get that error.
Do I need to change anything else?

@carstene1ns
Copy link
Member

Clone just the psplibraries repo and run ./libraries.sh SDL.

@stefanmielke
Copy link

stefanmielke commented May 15, 2021

Same error on different libs now:

iniparser.c:(.text+0x10c): undefined reference to '__ctype_ptr__'
iniparser.c:(.text+0x114): undefined reference to '__ctype_ptr__'
/usr/local/pspdev/psp/sdk/lib/libpspirkeyb.a(iniparser.o): In function 'strlwc.part.0':
iniparser.c:(.text+0x160): undefined reference to '__ctype_ptr__'
iniparser.c:(.text+0x164): undefined reference to '__ctype_ptr__'
/usr/local/pspdev/psp/sdk/lib/libpspirkeyb.a(iniparser.o): In function 'iniparser_new':
(.text+0xdd8): undefined reference to '__ctype_ptr__'
/usr/local/pspdev/psp/sdk/lib/libpspirkeyb.a(iniparser.o):(.text+0xe00): more undefined references to '__ctype_ptr__' follow```

@carstene1ns
Copy link
Member

I know it is a bit tedious, but you need the same for every other lib as well.
(just ./libraries.sh pspirkeyb [other libs you use])

@stefanmielke
Copy link

That one more did the trick, thanks!

Do you have a way to push these changes so we can automate this build? Not sure what I'd need to do here.

@carstene1ns
Copy link
Member

First of all: Thank you for your patience! :)

What would need to be done is testing the updated newlib on hardware. Does your project run now?
Then I can switch branches easily.

@stefanmielke
Copy link

Well, it builds, not really runs though (investigating why now)

Although it only worked on PPSSPP and crashed on real hardware (I think it's something due to the ways it handles files, as we use StormLib).

@carstene1ns
Copy link
Member

I guess I need to try a basic example then, however, currently no access to a PSP. :/

@stefanmielke
Copy link

Looks like some of the samples I've tested are working, unfortunately I have no SDL samples to test (btw kernel/fileio is crashing).

@sharkwouter
Copy link
Member

I know this game uses SDL, but I'm not sure if it still builds, since it isn't updated much: https://github.com/sergiou87/open-supaplex

@stefanmielke
Copy link

stefanmielke commented May 16, 2021

I know this game uses SDL, but I'm not sure if it still builds, since it isn't updated much: https://github.com/sergiou87/open-supaplex

Same problem mine have. Just a black screen forever (no crashes). Both on PPSSPP and real hardware.

It does build without issues.

@wally4000
Copy link
Contributor

Fixed in current toolchain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants