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

Status
Not open for further replies.

andromeda

Well-known member
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.
 
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";
 
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 ?
 
Is this properly declared before use? : variables m_sProtocolVersion are declared as std::string m_sProtocolVersion;
 
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;
 
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
 
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.
 
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
 
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.
 
Status
Not open for further replies.
Back
Top