7 years, 6 months ago.

How do I enable C++11 support in mbed-os 5 CLI?

Title says it all.

Answer as of mBed OS 5.2

Now the settings are more easy to edit. They are stored in a JSON file: ./mbed-os/tools/profiles/debug.json and default.json.

Old Answer

So it seems like it is hardcoded in mbed-os\tools\toolchains\gcc.py

    # ANY changes to these default flags is backwards incompatible and require
    # an update to the mbed-sdk-tools and website that introduces a profile
    # for the previous version of these flags
    DEFAULT_FLAGS = {
        'common': ["-c", "-Wall", "-Wextra",
            "-Wno-unused-parameter", "-Wno-missing-field-initializers",
            "-fmessage-length=0", "-fno-exceptions", "-fno-builtin",
            "-ffunction-sections", "-fdata-sections", "-funsigned-char",
            "-MMD", "-fno-delete-null-pointer-checks", "-fomit-frame-pointer"
            ],
        'asm': ["-x", "assembler-with-cpp"],
        'c': ["-std=gnu99"],
        'cxx': ["-std=gnu++98", "-fno-rtti", "-Wvla"],
        'ld': ["-Wl,--gc-sections", "-Wl,--wrap,main",
            "-Wl,--wrap,_malloc_r", "-Wl,--wrap,_free_r", "-Wl,--wrap,_realloc_r", "-Wl,--wrap,_calloc_r",
            "-Wl,--wrap,exit", "-Wl,--wrap,atexit"],
    }

Changing gnu++98 to gnu++11 works, but this is really ugly. It'd be nice if someone could fix this (or just set gnu++11 by default. Come on it's 2016!!!)

1 Answer

7 years, 6 months ago.

Hi Tim,

That's the bit you need to change, yes. The main reason why C++11 support is not on by default is that not all of the compilers that we support have C++11 support.

There's currently some work being done on GitHub to make it easier to edit the compiler flags: https://github.com/ARMmbed/mbed-os/pull/2802

It's not merged yet, but if it is you'll be able to create custom "build profiles" and tailor the compiler flags however you like. Because we can't test every combination of these flags, do know that all things might not play nicely together depending on what you tweak. But hopefully that'll give you the freedom to at least give it a try! So keep on eye on the GitHub repo!

Hope that helps!

Brian

Accepted Answer