0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

mbedOS6で303k8にてto_stringを書くとコンパイルエラーになる

Last updated at Posted at 2024-05-29

躓いたのでメモ

環境

  • IDE: Keil Studio
  • mbed-os 6.15.1
  • Build Target: NUCLEO-F303K8

コード

main.cpp
#include "mbed.h"
#include <string>
// main() runs in its own thread in the OS
int main()
{
    std::string str = std::to_string(123);
    while (true) {

    }
}

症状

以下のような表示が出てコンパイルできない

Warning: L3912W: Option 'legacyalign' is deprecated.
Error: L6218E: Undefined symbol __2swprintf (referred from /opt/ARMCompiler6.15.13/bin/../lib/libcxx/libcpp_w.l(string.cpp.o)).
Error: L6218E: Undefined symbol wcslen (referred from /opt/ARMCompiler6.15.13/bin/../lib/libcxx/libcpp_w.l(string.cpp.o)).
Error: L6218E: Undefined symbol wcstol (referred from /opt/ARMCompiler6.15.13/bin/../lib/libcxx/libcpp_w.l(string.cpp.o)).
Error: L6218E: Undefined symbol wcstoll (referred from /opt/ARMCompiler6.15.13/bin/../lib/libcxx/libcpp_w.l(string.cpp.o)).
Error: L6218E: Undefined symbol wcstoul (referred from /opt/ARMCompiler6.15.13/bin/../lib/libcxx/libcpp_w.l(string.cpp.o)).
Error: L6218E: Undefined symbol wcstoull (referred from /opt/ARMCompiler6.15.13/bin/../lib/libcxx/libcpp_w.l(string.cpp.o)).
Error: L6218E: Undefined symbol wmemchr (referred from /opt/ARMCompiler6.15.13/bin/../lib/libcxx/libcpp_w.l(string.cpp.o)).
Error: L6218E: Undefined symbol wmemcmp (referred from /opt/ARMCompiler6.15.13/bin/../lib/libcxx/libcpp_w.l(string.cpp.o)).
Error: L6218E: Undefined symbol wmemcpy (referred from /opt/ARMCompiler6.15.13/bin/../lib/libcxx/libcpp_w.l(string.cpp.o)).
Error: L6218E: Undefined symbol wmemmove (referred from /opt/ARMCompiler6.15.13/bin/../lib/libcxx/libcpp_w.l(string.cpp.o)).
Error: L6218E: Undefined symbol wmemset (referred from /opt/ARMCompiler6.15.13/bin/../lib/libcxx/libcpp_w.l(string.cpp.o)).
Error: L6218E: Undefined symbol __wcstod_int (referred from /opt/ARMCompiler6.15.13/bin/../lib/armlib/m_wm.l(wcstod.o)).
Error: L6218E: Undefined symbol __wcstof_int (referred from /opt/ARMCompiler6.15.13/bin/../lib/armlib/m_wm.l(wcstof.o)).
Finished: 0 information, 1 warning and 13 error messages.
Internal error.
Internal error.
Build failed
Build failed

対処法

プロジェクト直下に mbed_app.json を追加し,以下を記述する

mbed_app.json
{
 "requires": ["bare-metal"],
 "target_overrides": {
   "*": {
     "target.c_lib": "std"
   }
 }
}

原因など

一部のマイコンで,cのライブラリを一部しか読みだしていないらしい.実際,mbed_os/targets/targets.jsonを見てみると,1637行目付近に

mbed_os/targets/targets.json
 "MCU_STM32F303x8": {
        "inherits": [
            "MCU_STM32F3"
        ],
        "public": false,
        "c_lib": "small",
        "extra_labels_add": [
            "STM32F303x8"
        ],
        "macros_add": [
            "STM32F303x8"
        ]
    },
    "NUCLEO_F303K8": {
        "inherits": [
            "MCU_STM32F303x8"
        ],
        "overrides": {
            "clock_source": "USE_PLL_HSI",
            "lse_available": 0
        },
        "detect_code": [
            "0775"
        ],
        "device_name": "STM32F303K8Tx"
    },

などと書いてあり,c_libがsmallに設定されている.

どうもこれは公式で推奨されている設定らしい.
https://os.mbed.com/docs/mbed-os/v6.16/bare-metal/using-small-c-libraries.html

古いマイコンなのでプログラム容量を削減したいなど色々あるだろうが,ぱっとは原因が分からないのでもう少し親切に警告等を出してくれると嬉しい

類似事例, 参考文献

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?