Undefined reference to std::basic_string with new version

Hi. I have a problem that I hoped you could help me with.

I have an older project that I worked on using Arduino IDE 1.5.7 with an added “-std=gnu++11” compile flag and I recently decided to update to a newer IDE version, but I can’t get the program to compile. I’ve tried Arduino IDE 1.8.0 and 1.6.13 but I get the same problem which seems to be related to the usage of std::string.

undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'

undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'

undefined reference to `std::string::_Rep::_S_empty_rep_storage'

undefined reference to `std::basic_string

So why have this stopped working on the new Arduino version and is there any simple way to fix this? If the answer is to remove all instances of std::string and use Arduinos String instead then I have to stick to the old IDE.

The arduino is a Due.

All input is greatly appreciated! :slight_smile:

Did you by any chance declare your strings? I think that might be the problem. Also, if you can post the code that would be great.

I’m not quite sure what you mean by declaring my strings. Could you elaborate?

The code is 10000+ lines of code so I don’t think that would be useful, but an example of a line that triggers the error is:

return std::string("N/A");

I was reading off the Arduino website about strings that is where I thought that maybe you need to declare the strings. https://www.arduino.cc/en/Reference/String

However, after searching the web a bit more, I think that might not be the problem. I did find some issues with people who were having similar issues while programming with C++. And the common solution to those issues seemed to be that they were linked with gcc instead of g++. Since I am not that experienced with Arduino, I do not know if something like that applies to Arduino

Yes since it works fine in the earlier version it probably something with the linker parameters in the newer one, but as far as I can tell it looks like its using g++ in the correct places.

I can now see that its linking with "arm-none-eabi-gcc.exe". Should it be "arm-none-eabi-g++.exe" instead? If so, where can I change this parameter?

AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-gcc" -mcpu=cortex-m3 -mthumb -Os -Wl,--gc-sections...

That could be a possibility but I am not sure in that regard (Sorry). Are you using any libraries if so, which ones?

No third party libraries.