Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined reference to `swprintf' #405

Open
lefebvresam opened this issue Dec 18, 2024 · 4 comments
Open

undefined reference to `swprintf' #405

lefebvresam opened this issue Dec 18, 2024 · 4 comments

Comments

@lefebvresam
Copy link

Using C++20 option std::format:

uint8_t Display::getVersion(string& version) {
    struct image_version iver;
    if (boot_get_current_version(&iver)) {
        ERROR("Cannot read version number");
        return 1;
    }
    version = std::format("%u.%u.%u+%lu", iver.iv_major, iver.iv_minor, +iver.iv_revision, +iver.iv_build_num);
    return 0;
}

gives:

/usr/local/gcc-arm/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld: /usr/local/gcc-arm/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/lib/thumb/v8-m.main+fp/softfp/libc_nano.a(libc_a-wcsftime.o): in function `__strftime.isra.0':
wcsftime.c:(.text.__strftime.isra.0+0x2fa): undefined reference to `swprintf'
/usr/local/gcc-arm/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld: wcsftime.c:(.text.__strftime.isra.0+0x32c): undefined reference to `swprintf'
/usr/local/gcc-arm/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld: wcsftime.c:(.text.__strftime.isra.0+0x390): undefined reference to `swprintf'
/usr/local/gcc-arm/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld: wcsftime.c:(.text.__strftime.isra.0+0x608): undefined reference to `swprintf'
/usr/local/gcc-arm/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld: wcsftime.c:(.text.__strftime.isra.0+0x700): undefined reference to `swprintf'
/usr/local/gcc-arm/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld: /usr/local/gcc-arm/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/lib/thumb/v8-m.main+fp/softfp/libc_nano.a(libc_a-wcsftime.o):wcsftime.c:(.text.__strftime.isra.0+0x834): more undefined references to `swprintf' follow
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
@JohnK1987
Copy link
Member

  1. you are using c++20 what is not officially supported in Mbed as i remember.
  2. I remember you had set "target.c_lib": "small". Have you also tried "target.c_lib": "std"?

@lefebvresam
Copy link
Author

lefebvresam commented Dec 18, 2024

Then I have:

l/build/develop/memory_banks.json
/usr/local/gcc-arm/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld: source/hmc20.elf section `.text' will not fit in region `FLASH'
/usr/local/gcc-arm/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld: region `FLASH' overflowed by 71436 bytes
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
Building failed

Alternative is old school but ugly:

uint8_t Display::getVersion(string& version) {
    struct image_version iver;
    if (boot_get_current_version(&iver)) {
        ERROR("Cannot read version number");
        return 1;
    }
    if (version.capacity() < 20) {
        ERROR("The string has not enough capacity");
        return 1;
    }
    sprintf(version.data(), "%u.%u.%u+%lu", +iver.iv_major, +iver.iv_minor, +iver.iv_revision, +iver.iv_build_num);
    return 0;
}

@JohnK1987
Copy link
Member

The new error is probably related to the change from small to std because the std occupied more flash memory.

@lefebvresam
Copy link
Author

I try to avoid advanced libs like streaming operator << etc, it will dramatically increase memory use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants