Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 15 of 15

Thread: std::deque Won't Compile for Teensy 3.x

  1. #1
    Senior Member
    Join Date
    Feb 2017
    Posts
    423

    std::deque Won't Compile for Teensy 3.x

    Hi All. Really simple MRE here. Arduino / Teensyduino 1.8.15 / 1.54
    Code:
    #include <Arduino.h>
    #include <deque>
    
    std::deque<uint8_t> myQueue;
    
    void setup() {
      myQueue.push_back(100);
    }
    
    void loop() {
    }
    Error Message:
    Code:
    d:/arduino-1.8.15/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/lib/armv7e-m/fpu\libc.a(lib_a-writer.o): In function `_write_r':
    writer.c:(.text._write_r+0x12): undefined reference to `_write'
    collect2.exe: error: ld returned 1 exit status
    Error compiling for board Teensy 3.5.
    It does compile for T4.x (and ESP32 / SAMD for that matter). But, I don't have a board to test it. Any suggestions?
    Thanks.

  2. #2
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,766
    It also fails for T3.2 with 1.8.16 and 1.56 beta 1

    Pete

  3. #3
    Senior Member
    Join Date
    Mar 2017
    Location
    Oakland, CA, USA
    Posts
    349
    Is something trying to call “printf”? You can define your own _write, if so, like this: https://forum.pjrc.com/threads/28473...l=1#post266068

    I’m curious if that helps.

  4. #4
    Senior Member
    Join Date
    Feb 2017
    Posts
    423
    Quote Originally Posted by shawn View Post
    Is something trying to call “printf”? You can define your own _write, if so, like this: https://forum.pjrc.com/threads/28473...l=1#post266068

    I’m curious if that helps.
    Yes, it definitely appears related.
    Thanks.

  5. #5
    Senior Member BriComp's Avatar
    Join Date
    Apr 2014
    Location
    Cheltenham, UK
    Posts
    459
    Hi All. Really simple MRE here. Arduino / Teensyduino 1.8.15 / 1.54
    What's an MRE?

  6. #6
    Senior Member
    Join Date
    Feb 2017
    Posts
    423
    Quote Originally Posted by BriComp View Post
    What's an MRE?
    (M)inimal (R)eproduceable (E)xample

  7. #7
    Senior Member BriComp's Avatar
    Join Date
    Apr 2014
    Location
    Cheltenham, UK
    Posts
    459
    Oh, OK.
    I tried googling it but could not find anything relevant.

  8. #8
    Junior Member
    Join Date
    Sep 2021
    Posts
    18
    Hi guys,

    I have a partial answer to this issue.

    firstly here is my setup...

    teensy 3.6
    visual studio 2019
    visual studio v micro extension ( Arduino & teensy support in visual studio).

    if I use release mode and compile it... it fails.

    Click image for larger version. 

Name:	compile failure.jpg 
Views:	24 
Size:	141.8 KB 
ID:	26058

    if I use debug mode it compiles just fine.

    Click image for larger version. 

Name:	compile sucess.jpg 
Views:	20 
Size:	144.2 KB 
ID:	26059

    This leaves me to believe that it's a linking problem possibly a link time optimisation, I also think that in debug mode ALL optimisation is turned off (please correct this if I am wrong). Additionally if I use any compile option that uses an LTO (Link time optimisation) option I get additional errors.

    Click image for larger version. 

Name:	compile failure2.jpg 
Views:	28 
Size:	156.6 KB 
ID:	26060

    I hope this information is of help to somebody

    best regards

    Simon.M
    Last edited by Simon.M; 10-03-2021 at 11:17 AM. Reason: just spelling and formatting

  9. #9
    Junior Member
    Join Date
    Jun 2014
    Posts
    15
    I am seeing a similar issue (same error message) which I suspect may be related to yours. I'm just using the Arduino IDE, nothing fancy. See https://forum.pjrc.com/threads/68366...174#post290174. Unfortunately I don't have an answer for either of us at this time. I'm pretty sure this problem did not exist in some earlier version of Arduino or Teensyduino, because I successfully wrote some very similar code a year or two ago.
    Last edited by jwhoag; 10-04-2021 at 09:20 AM. Reason: Disabled smileys/corrected spelling error

  10. #10
    Junior Member
    Join Date
    Sep 2021
    Posts
    18
    hi jwhoag,

    If you look at the last image in my last post, from the way it reads. start from the very first line and it says "error linking for board teensy3.6". To me that means it compiled, but failed to put all the bits (main code + libraries) into one file. I am reasonably sure it's going be something like a compiler option that needs changing. This usually ends up being a command line option. Most of the IDE's that i have seen use a dos style command line compiler in the background.

    The hard part is locating which of the command line option causes this issue.

    This is just my opinion from limited information in the error messages seen in visual studio.

    best regards

    Simon.M

  11. #11
    Member
    Join Date
    Sep 2021
    Posts
    74
    Quote Originally Posted by Simon.M View Post
    hi jwhoag,

    If you look at the last image in my last post, from the way it reads. start from the very first line and it says "error linking for board teensy3.6". To me that means it compiled, but failed to put all the bits (main code + libraries) into one file. I am reasonably sure it's going be something like a compiler option that needs changing. This usually ends up being a command line option. Most of the IDE's that i have seen use a dos style command line compiler in the background.

    The hard part is locating which of the command line option causes this issue.

    This is just my opinion from limited information in the error messages seen in visual studio.

    best regards

    Simon.M
    It enough to just add a Serial.println() somewhere to the code. No commandline option can do that.

  12. #12
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,643
    There is a weird linker issue which sometimes doesn't link in _write (which is defined in print.cpp). You can work around this by placing a dummy Serial.println("") into startup. There are some posts about this in the forum... Not nice but works.

    Edit: ups, crosspost

  13. #13
    Junior Member
    Join Date
    Sep 2021
    Posts
    18
    Hi All,

    finally found a solution...

    go to the tools menu and choose optimise "smallest code", This works for this issue and the issue on this post
    https://forum.pjrc.com/threads/68366...174#post290174

    Both compile on Arduino 1.8.13 using optimise "smallest code".

    Click image for larger version. 

Name:	arduino deque compiled ok.jpg 
Views:	19 
Size:	52.0 KB 
ID:	26069

    best regards

    Simon.M
    Last edited by Simon.M; 10-04-2021 at 01:09 PM. Reason: formatting to tidy up the post

  14. #14
    Junior Member
    Join Date
    Jun 2014
    Posts
    15
    The smallest code option works for me too. Thanks!

  15. #15
    Junior Member
    Join Date
    Jun 2014
    Posts
    15
    Mcu32: Your idea crossed my mind before I even came to this forum. I added Serial.print("hi"); to my code, but the problem persisted so I discarded that idea. But once I read your comment I noticed your solution was to add Serial.println, so I tried that instead and found that yes, Serial.println does resolve the issue, but Serial.print does not. That could be an interesting clue if someone is looking into a proper resolution for this issue.

    If I were to venture a guess at what the root problem is, I'd look to see if there might be some debug code somewhere that perhaps does not get completely optimized out unless the more stringent code removal algorithm ("Smallest Code") is selected. And for your solution, println apparently actually uses the _write_r function for whatever reason, so it's not marked for removal by the optimizer, and thus the errantly remaining debug code can link. Imagination space there for a moment.

    Anyway, thanks guys, I now have two solutions that work!
    --Jeff

Posting Permissions

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