Odd linker errors if std::string defined or used inside loop (mbed 6.2.1, STM32F303RE)

Board: Nucleo F303RE
Mbed Version: 6.2.1
Method: Mbed Studio

I’m getting linker errors if I define a std::string inside a loop. Originally I discovered this while trying to allocate a std::string* for try_alloc from a Mail object, but it also happens with non-pointer objects as in this example:

void testthread()
{
   //no linker errors
    std::string test_str;

    while(true)

    {
        //linker error
        std::string test_str2;

    }

}

Results in the following linker errors:

Link: mbed-os6-test-Mail-stdstring
[Warning] @0,0: L3912W: Option ‘legacyalign’ is deprecated.
[Error] @0,0: L6218E: Undefined symbol __2swprintf (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\libcxx\libcpp_w.l(string.cpp.o)).
[Error] @0,0: L6218E: Undefined symbol wcslen (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\libcxx\libcpp_w.l(string.cpp.o)).
[Error] @0,0: L6218E: Undefined symbol wcstol (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\libcxx\libcpp_w.l(string.cpp.o)).
[Error] @0,0: L6218E: Undefined symbol wcstoll (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\libcxx\libcpp_w.l(string.cpp.o)).
[Error] @0,0: L6218E: Undefined symbol wcstoul (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\libcxx\libcpp_w.l(string.cpp.o)).
[Error] @0,0: L6218E: Undefined symbol wcstoull (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\libcxx\libcpp_w.l(string.cpp.o)).
[Error] @0,0: L6218E: Undefined symbol wmemchr (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\libcxx\libcpp_w.l(string.cpp.o)).
[Error] @0,0: L6218E: Undefined symbol wmemcmp (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\libcxx\libcpp_w.l(string.cpp.o)).
[Error] @0,0: L6218E: Undefined symbol wmemcpy (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\libcxx\libcpp_w.l(string.cpp.o)).
[Error] @0,0: L6218E: Undefined symbol wmemmove (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\libcxx\libcpp_w.l(string.cpp.o)).
[Error] @0,0: L6218E: Undefined symbol wmemset (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\libcxx\libcpp_w.l(string.cpp.o)).
[Error] @0,0: L6218E: Undefined symbol __wcstod_int (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\armlib\m_wm.l(wcstod.o)).
[Error] @0,0: L6218E: Undefined symbol __wcstof_int (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\armlib\m_wm.l(wcstof.o)).
Warning: L3912W: Option ‘legacyalign’ is deprecated.
Error: L6218E: Undefined symbol __2swprintf (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\libcxx\libcpp_w.l(string.cpp.o)).
Error: L6218E: Undefined symbol wcslen (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\libcxx\libcpp_w.l(string.cpp.o)).
Error: L6218E: Undefined symbol wcstol (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\libcxx\libcpp_w.l(string.cpp.o)).
Error: L6218E: Undefined symbol wcstoll (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\libcxx\libcpp_w.l(string.cpp.o)).
Error: L6218E: Undefined symbol wcstoul (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\libcxx\libcpp_w.l(string.cpp.o)).
Error: L6218E: Undefined symbol wcstoull (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\libcxx\libcpp_w.l(string.cpp.o)).
Error: L6218E: Undefined symbol wmemchr (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\libcxx\libcpp_w.l(string.cpp.o)).
Error: L6218E: Undefined symbol wmemcmp (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\libcxx\libcpp_w.l(string.cpp.o)).
Error: L6218E: Undefined symbol wmemcpy (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\libcxx\libcpp_w.l(string.cpp.o)).
Error: L6218E: Undefined symbol wmemmove (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\libcxx\libcpp_w.l(string.cpp.o)).
Error: L6218E: Undefined symbol wmemset (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\libcxx\libcpp_w.l(string.cpp.o)).
Error: L6218E: Undefined symbol __wcstod_int (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\armlib\m_wm.l(wcstod.o)).
Error: L6218E: Undefined symbol __wcstof_int (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\armlib\m_wm.l(wcstof.o)).
Finished: 0 information, 1 warning and 13 error messages.
[ERROR] Warning: L3912W: Option ‘legacyalign’ is deprecated.
Error: L6218E: Undefined symbol __2swprintf (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\libcxx\libcpp_w.l(string.cpp.o)).
Error: L6218E: Undefined symbol wcslen (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\libcxx\libcpp_w.l(string.cpp.o)).
Error: L6218E: Undefined symbol wcstol (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\libcxx\libcpp_w.l(string.cpp.o)).
Error: L6218E: Undefined symbol wcstoll (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\libcxx\libcpp_w.l(string.cpp.o)).
Error: L6218E: Undefined symbol wcstoul (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\libcxx\libcpp_w.l(string.cpp.o)).
Error: L6218E: Undefined symbol wcstoull (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\libcxx\libcpp_w.l(string.cpp.o)).
Error: L6218E: Undefined symbol wmemchr (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\libcxx\libcpp_w.l(string.cpp.o)).
Error: L6218E: Undefined symbol wmemcmp (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\libcxx\libcpp_w.l(string.cpp.o)).
Error: L6218E: Undefined symbol wmemcpy (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\libcxx\libcpp_w.l(string.cpp.o)).
Error: L6218E: Undefined symbol wmemmove (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\libcxx\libcpp_w.l(string.cpp.o)).
Error: L6218E: Undefined symbol wmemset (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\libcxx\libcpp_w.l(string.cpp.o)).
Error: L6218E: Undefined symbol __wcstod_int (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\armlib\m_wm.l(wcstod.o)).
Error: L6218E: Undefined symbol __wcstof_int (referred from c:\Users\kuutei\AppData\Local\Mbed Studio\mbed-studio-tools\ac6\bin..\lib\armlib\m_wm.l(wcstof.o)).
Finished: 0 information, 1 warning and 13 error messages.

Other types like uint32_t and std::vector can also be created in a loop without issue.

edit:
Even use of a std::string ANYWHERE seems to cause issues:

void testthread()
{
    //no linker errors
    std::string test_str;

    //linker errors
    test_str = "value";

    while(true)
    {
		//linker errors
        test_str = "test";
    }
}

edit2: No problems on mbed 5.15 with either example.

Have you managed to solve the problem? What was the solution?

I’m still seeing the issue with the latest patch for mbed-os 6.2.1.

My solution was to switch back to 5.15.

edit: seems to be an issue for some STM32 boards. When I try to build for various boards (I don’t own them to actually test, I just compiled to binaries):
STM32F411: linker error
STM32L432KC: linker error
STM32F303RE: linker error
STM32F103RB: linker error
STM32F091: linker error

STM32F746: no errors
STM32F747: no errors
FRDM-K64F: no errors
nRF52-DK: no errors

After the last Mbed Studio update (08.09.2020CET; Mbed Studio 1.2.1; mbed-os 6.2.1) it started to work. I’ve tested it on Nucleo-F207ZG and Nucleo-F746ZG boards.

I’m still seeing issues with F303RE, can you try compiling for it? (just the build, not running it)

As far as I can tell I’m on the latest mbed studio version and mbed-os 6.2.1 update.

I’m using a STM32L432KC and I get spurious linker errors using mbed OS 6.3.0 and Tools 1.2.1 - I’ve just updated my code base to OS6 and tried to run it on the STM32L432KC board and no dice…

EDIT: reworking my code to remove dependencies on “iostream” stopped these errors and allowed the code to build and deploy successfully

[Error] @0,0: L6218E: Undefined symbol wmemcpy (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(ios.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol wmemset (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(ios.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol __ARM_snprintf (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(locale.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol __ARM_vasprintf (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(locale.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol __ARM_vsnprintf (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(locale.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol __ARM_vsscanf (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(locale.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol _mbsnrtowcs (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(locale.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol _wcsnrtombs (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(locale.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol btowc (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(locale.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol iswalpha (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(locale.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol iswblank (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(locale.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol iswcntrl (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(locale.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol iswdigit (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(locale.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol iswlower (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(locale.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol iswprint (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(locale.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol iswpunct (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(locale.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol iswspace (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(locale.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol iswupper (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(locale.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol iswxdigit (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(locale.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol mbrlen (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(locale.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol mbsrtowcs (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(locale.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol mbtowc (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(locale.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol towlower (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(locale.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol towupper (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(locale.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol wcscoll (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(locale.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol wcsxfrm (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(locale.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol wctob (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(locale.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol __2swprintf (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(string.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol wcslen (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(string.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol wcstol (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(string.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol wcstoll (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(string.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol wcstoul (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(string.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol wcstoull (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(string.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol wmemchr (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(string.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol wmemcmp (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(string.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol wmemmove (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\libcxx\libcpp_w.l(string.cpp.o)).

[Error] @0,0: L6218E: Undefined symbol __wcstod_int (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\armlib\m_wm.l(wcstod.o)).

[Error] @0,0: L6218E: Undefined symbol __wcstof_int (referred from c:\ProgramData\Mbed Studio\mbed-studio-tools\ac6\bin\..\lib\armlib\m_wm.l(wcstof.o)).
1 Like

I have the exact same issue as kuutei, also using a F303RE and the latest Mbed Studio update. Tried every version 6.* but did not work, was forced to go back to 5.15.

Has anyone figured out how to fix this?

1 Like

I had a look in the board support targets for mbed OS 6.3 https://github.com/ARMmbed/mbed-os/blob/master/targets/targets.json and noticed that for my board there is an entry;

"NUCLEO_L432KC": {
    "inherits": [
        "MCU_STM32L4"
    ],
    "c_lib": "small",
    "extra_labels_add": [
        "STM32L432xC",
        "STM32L432KC"
    ],
    "macros_add": [
        "STM32L432xx"
    ],
    "detect_code": [
        "0770"
    ],
    "device_name": "STM32L432KC"
},

and the F303RE also has the “c_lib” : “small” directive… I assume that is why the larger libraries such as (streamio) don’t work as the linker would have no source to link to. In contrast, the STMF401RE board I’ve had for ages, has no such directive - hence my problems when transferring code from the 401 to the 432 - annoying, but do-able.

EDIT: hahaha, well, I edited the JSON for the 432, put the (iostream) back in and also the std::string example above and it compiles and links just fine. Grrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr! I wasted a couple of hours on recoding this for nothing! Must be a bug in the bare-metal option in mbed 6.x…

1 Like

Hi
Seems there is some discussion about this small lib topic in NUCLEO_F303RE with ESP8266 failed to connect WIFI · Issue #13687 · ARMmbed/mbed-os · GitHub

2 Likes

Which JSON did you edit and how did you edit it? I am currently facing the same issue with the 432. Looking forward to your response!