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

Thread: [teensy 3.6] using string.erase or string.insert generate basic_string error

  1. #1

    [teensy 3.6] using string.erase or string.insert generate basic_string error

    hi,

    using this code below i have errors compilation

    Code:
    #include <string>
    
    ...
    
    void CHTTP::SetProtocolVersion(CSockProtocol protocol)
    {
      switch (protocol)
      {
        case HTTP10:
          m_sProtocolVersion.erase();
          m_sProtocolVersion.insert(0, "HTTP/1.0");
          break;
    
        case HTTP11:
          m_sProtocolVersion.erase();
          m_sProtocolVersion.insert(0, "HTTP/1.1");
          break;
    
        default:
          m_sProtocolVersion.erase();
          m_sProtocolVersion.insert(0, "HTTP/1.1");
          break;
      }
    }
    
    variables m_sProtocolVersion are declared as  std::string m_sProtocolVersion;
    
    
    Compilation errors:
    
    d:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\c++\5.4.1\bits/basic_string.h:1659: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_replace(unsigned int, unsigned int, char const*, unsigned int)'
    
    d:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\c++\5.4.1\bits/basic_string.h:1659: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_replace(unsigned int, unsigned int, char const*, unsigned int)'
    
    d:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\c++\5.4.1\bits/basic_string.h:1659: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_replace(unsigned int, unsigned int, char const*, unsigned int)'
    I read in a forum that it was possible to avoid this by adding a compilation directive but I do not know or put it, maybe in the file platfomr.txt?
    the directive is -D_GLIBCXX_USE_CXX11_ABI=0

    i need to use std::string because is an old program.

    Has someone already had this problem

    i use teensy 3.6 last version and arduino last version.

    Thanks for your help.

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    12,177
    not a string user - but a search suggests erase() with no params will NULL the string? And then insert(...) would just attempt to set the string to the supplied value.

    Perhaps just replace the code with: the right variation of :: m_sProtocolVersion = "HTTP/1.0";

  3. #3
    this variation not work

    Code:
    //Set protocol version
    void CHTTP::SetProtocolVersion(CSockProtocol protocol)
    {
      switch (protocol)
      {
        case HTTP10:      
          ::m_sProtocolVersion = "HTTP/1.0";
          break;
    
        case HTTP11:     
          ::m_sProtocolVersion = "HTTP/1.1";
          break;
    
        default:      
          ::m_sProtocolVersion = "HTTP/1.1";
          break;
      }
    }
    
    CHTTP.cpp:105: error: '::m_sProtocolVersion' has not been declared
           ::m_sProtocolVersion = "HTTP/1.0";
    
           ^
    
    CHTTP.cpp:109: error: '::m_sProtocolVersion' has not been declared
           ::m_sProtocolVersion = "HTTP/1.1";
    
           ^
    
    CHTTP.cpp:113: error: '::m_sProtocolVersion' has not been declared
           ::m_sProtocolVersion = "HTTP/1.1";
    
           ^
    
    '::m_sProtocolVersion' has not been declared
    the problem is the compilator.

    i have test to put at top of file template class std::basic_string<char>; and is a same.

    any idea ?

  4. #4
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    12,177
    Is this properly declared before use? : variables m_sProtocolVersion are declared as std::string m_sProtocolVersion;

  5. #5
    yes is declared before use

    Code:
    int m_iRemoteSrvPort;
        int m_nHTTPLastStatusCode;
        
        std::string m_sProtocolVersion;
        long m_nRcvBufLen;

    i don't untersdand because the code below work

    Code:
    //Setting url
    void CHTTP::SetUrl(const char* url)
    {  
      m_sUrl = url;
    }
    
    m_sUrl is defined as    std::string m_sUrl;

  6. #6
    may be missing a header include ?

    d:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\c++\5.4.1\bits/basic_string.h:1243: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_replace(unsigned int, unsigned int, char const*, unsigned int)'

    collect2.exe: error: ld returned 1 exit status

  7. #7
    the problem is a linker std::__cxx11

  8. #8
    I can replace std :: string by String but I wanted to know why std :: string does not work, someone can do a test on two lines of code to know if it works.

  9. #9
    I replaced std: string by String now everything works but I think there is a g++ version problem with c++ 11 parameters CFLAGS in the teensy 3.6 compilation settings at the boards.txt file

  10. #10
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    12,177
    Not surprising - possibly by design to limit or control the code that can be included and used for safety here in the generally smaller is better embedded world.

Posting Permissions

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