Forum Rule: Always post complete source code & details to reproduce any issue!
Page 1 of 2 1 2 LastLast
Results 1 to 25 of 26

Thread: to_string() doesn't work

  1. #1

    to_string() doesn't work

    the std string library function to_string() don't work, "not declared in this scope"
    Click image for larger version. 

Name:	Teensy to_string().jpg 
Views:	47 
Size:	76.3 KB 
ID:	24199

  2. #2
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,856
    String(zahl) ? why are you using strings? use character arrays, uses less resources without the heap destructions

  3. #3
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,058
    Hm, my arduino does not allow to paste a sreenshot :-(

  4. #4
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,190
    see this thread: https://forum.pjrc.com/threads/46866-string-help

    Also posting an image of your code makes it impossible to copy and paste the code into an IDE window - few are going
    to help you if you force them to type in your code by hand(!)

  5. #5
    Here the code:
    #include <string>
    using namespace std;

    uint8_t zahl = 10;
    string zahlString;

    void setup() {
    zahlString = to_string(zahl);
    }

    void loop() {

    }
    I don't want to discuss the use of String, string or char arrays. It is simple why doesn't it work, it is standard c++11 function

  6. #6
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,607
    AFAIK you need to use at least GCC 6 for this. I just tested your code with gcc-arm-none-eabi-9-2019-q4. And it compiles without issue. There are a few discussions about this issue on Stackoverflow.

  7. #7
    Is there a simple way to change the compiler version? And why does Teensy use an old version? Normally I work on PlatformIO.

  8. #8
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,607
    https://github.com/TeensyUser/doc/wiki/GCC

    Scroll down to "Switching between different toolchains". I'm usually using VisualTeensy where switching is done by simply changing the setting for the GCC folder. If you find out how to do it in PlatformIO it would be great if you could add some info to the WIKI

  9. #9
    Tried with following .ini on platformIO
    Code:
    [env:teensy41]
    platform = teensy
    board = teensy41
    framework = arduino
    platform_packages = toolchain-gccarmnoneeabi@>1.90000.0
    getting following result
    Code:
    Linking .pio/build/teensy41/firmware.elf
    /Users/sstaub/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/bin/ld: cannot find -larm_cortexM7lfsp_math

  10. #10
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,607
    Yes, the Wiki link shows how to fix this

  11. #11
    I want to try it for Teensyduino app, but the wiki doesn't help me, I'm working on macOS. The path for Arduino/hardware/tools is different to windows.
    On mac there is a user folder Documents/Arduino/hardware which is empty and in Library/Arduino15/packages I can't find the files for Teensy.
    Maybe the Teensyduino IDE have another path on mac then the Arduino IDE.

  12. #12
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,190
    Stuff's in /Applications/Teensyduino.app/Contents/Java/hardware/teensy/ for me....

  13. #13
    Followed the wiki and changed to gcc-arm-none-eabi-9-2019-q4. No luck, I get always
    Code:
    cannot find -larm_cortexM7lfsp_math

  14. #14
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,607
    Looks like you didn't copy the libraries to the correct path? Unless the GCC folder structure is different for a MAC, they need to go into the MAC equivalent of this WIN10 folder:

    ...\gcc-arm-none-eabi-9_3-2020-q2\arm-none-eabi\lib

    Click image for larger version. 

Name:	Screenshot 2021-03-28 082935.jpg 
Views:	42 
Size:	66.2 KB 
ID:	24211

    Activating verbose output in Arduino and PIO should help finding the correct folders.
    Last edited by luni; 03-28-2021 at 08:09 AM.

  15. #15
    The file libarm_cortexM7lfsp_math.a is missing in gcc versions higher than 1.5 and must manually copied. wtf

  16. #16
    Senior Member
    Join Date
    Jul 2014
    Posts
    3,316
    Quote Originally Posted by sstaub View Post
    The file libarm_cortexM7lfsp_math.a is missing in gcc versions higher than 1.5 and must manually copied. wtf
    IMHO, If it is not there it should not be used!
    the fact that Arduino/Makefiles are not adapting to changing gcc is not the problem of gcc
    maybe there is an equivalent library, or installation of toolchain is not complete.

    BTW, even if you abbreviate to three letters, it is NOT cool to use insults on a technical forum.

  17. #17
    Are there any news about change of the toolchain to a newer version to solve this problem.

  18. #18
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    24,834
    Quote Originally Posted by sstaub View Post
    any news about change
    I can comment on this, but it's not going to be the answer you want.

    My 2 top priorities are flash encryption and debugging NativeEthernet. Both are large, daunting projects. I'm not even going to consider any toolchain change until both of those are done.

  19. #19
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,058
    Quote Originally Posted by sstaub View Post
    Are there any news about change of the toolchain to a newer version to solve this problem.
    Very easy to do it yourself: https://github.com/TeensyUser/doc/wi...ent-toolchains

  20. #20
    Quote Originally Posted by Frank B View Post
    I know how to do it but using a 5 year old compiler version as a standard?!

  21. #21
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    24,834
    The relatively old compiler still works quite well. It may be lacking some newer C++ features and may miss a few optimizations in -03 mode, but we know it works and gives very stable results. A huge code base has been thoroughly tested with this specific old version.

    So far, no newer version offers improved code speed. Frank and others have tested performance and found almost no improvement and in some cases slightly slower generated code by newer versions.

    Every toolchain upgrade comes with substantial risk, usually by exposing subtle bugs in various libraries which never mattered under the old compiler. While that's technically not the new compiler's fault, the practical reality is upgrading the toolchain requires a lot of beta testing. If old code breaks with the newer toolchain, it all needs to be updated before we can make the switch in a stable release.

    All that effort needs to be balanced against a huge list of other features, like improving MTP, many audio features people want, more USB host drivers, non-blocking I2C, and so on. While you probably feel these specific C++ features are important, in terms of making decisions where to invest limited dev time, those sorts of major features so many people want almost always take priority over messing with the toolchain.

    The net result is we tend to stay on older but highly stable toolchains, especially when newer ones produce slower or at best the same performance compiled code.

  22. #22
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,058
    So, regarding the compiler itself: I have seen that it sometimes generates faster code, but sometimes not. In total it comes out to about the same speed.
    What I like is that it generates a lot more warnings. Many of these are now also fixed in the libraries and teensy core.
    The stricter checking also produces (I'm just assuming) more "accurate" code that is closer to what the programmer tells GCC. Maybe this is the reason why some is compiled to slower code. Just a guess!

    The old toolchain has bugs that are now fixed. Especially "bad" I find the newlib sinf(x)/cosf(x) bug which leads to very slow calculations when x is large. There are workarounds for this - or the corresponding CMSIS function.
    This is fixed in newer versions. Probably new bugs were introduced for it. That's just the way it is. Old bugs are fixed and there are new ones.

    I use GCC10 as "default" and have not had any bad experiences so far.
    Besides, a lot has been done to C++. I personally haven't missed anything yet, and honestly - to_string() and similar are no reason to panic now.

    At the end of the day I think that an update of the toolchain is not urgent. But maybe you shouldn't wait for years with it.

  23. #23
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,058
    Quote Originally Posted by Frank B View Post
    I use GCC10 as "default" and have not had any bad experiences so far.
    Well.. a few minutes later:
    Code:
    Exception 0x8b04488b 0xccccccd5 0x8b64cccc 0x58004012
    PC=0x58004012
    
    runtime: unknown pc 0x58004012
    stack: frame={sp:0x3eba5800, fp:0x0} stack=[0x12448000,0x1244a000)
    
    runtime: unknown pc 0x58004012
    stack: frame={sp:0x3eba5800, fp:0x0} stack=[0x12448000,0x1244a000)
    
    eax     0x0
    ebx     0x58003ffd
    ecx     0x3ffed555
    edx     0x55555555
    edi     0x99999800
    esi     0x99999999
    ebp     0xbc084000
    esp     0x3eba5800
    eip     0x58004012
    eflags  0x40088265
    cs      0x57d93eba
    fs      0xb800ffff
    gs      0x0
    C:\Arduino\arduino-builder gab 2 zurück
    Fehler beim Kompilieren für das Board Teensy 4.1.
    a GCC 10 crash

  24. #24
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,607
    Wow, what did you feed it ?

  25. #25
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,058
    A *very* large project with the Audio codecs. It worked again when I cleaned the build...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •