C++11 in exported projects - again

18 Jan 2018

Previously, I asked:

Quote:

How can I use mbed-cli to set the language standard compiler option (e.g. -std=gnu++11) in my exported project? Is this settable via command line options? And/or via .json files?

Currently I'm using mbed export -m LPC4088 -i mcuxpresso.

If possible, please include an explanation and a link to references, so I can learn more. Thanks.

Jan Jongboom replied:

Quote:

You can do so using a build profile. Add -std=gnu++11 to your local build profile then export via:

mbed export -m LPC4088 -i mcuxpresso --profile=./path/to/local/profile.json

I think I "spoke" too soon by accepting that answer before.

When I do mbed export -h, there is no mention of a --profile option. And I can't find any documentation on the web about json files for mbed export.

Did Jan mix up mbed export with mbed build? Is there a way to export a file with C++11 enabled in the build options? Where is it documented?

22 Jan 2018

As far as I understand your question you want to build your project with C++11 instead of default C++98.

If you are building with "arm-none-eabi-gcc" like I do, then you have to do the following stuff:

  • copy the required profile (i.e. release.json) from "mbed-os\tools\profiles\*.json" to your main project folder (I wouldn't touch the default file)
  • and edit the following line from:

default release.json

[...]
    "GCC_ARM": {
[...]
        "cxx": ["-std=gnu++98", "-fno-rtti", "-Wvla"],
[...]

to

custom release.json

[...]
    "GCC_ARM": {
[...]
        "cxx": ["-std=gnu++11", "-fno-rtti", "-Wvla"],
[...]
  • then build your project from the command line in your main project folder with:

mbed compile command

mbed compile -m [your board] -t GCC_ARM --profile ./release.json
22 Jan 2018

Phillipp Steiner wrote:

As far as I understand your question you want to build your project with C++11 instead of default C++98.

Close. I'm not trying to build with mbed compile. I want to export to a project that will build with C++11. I'm currently exporting to NXP MCUXpresso, which uses arm-none-eabi-gcc. Later I plan to export to Visual Studio Code, still using arm-none-eabi-gcc.

As I said:

Brendan McDonnell wrote:

When I do mbed export -h, there is no mention of a --profile option. And I can't find any documentation on the web about json files for mbed export.

Did Jan mix up mbed export with mbed build? Is there a way to export a file with C++11 enabled in the build options? Where is it documented?

22 Jan 2018

Hi, seems like help does not show profile option..

but if you do

mbed export --profile release -m K64F -i IAR for instance , it should be functional

and release profile would contain the flag you need to enable c++11 in your case

22 Jan 2018

I don't think this profile feature for exports exists.

I copied mbed-os/tools/profiles/release.json to the root of my project folder, and changed "-std=gnu++98" to "-std=gnu++11" in the GCC_ARM section.

Per your suggestion, when I do mbed export --profile release -i mcuxpresso, it gives an error. When I use the full filename (mbed export --profile release.json -i mcuxpresso, or with the = as mbed export --profile=release.json -i mcuxpresso), it completes the export, but it has no effect on the exported project settings. There are still two build configurations (build and release), and both are still set to GNU++98.

(I have TARGET=lpc4088 in my .mbed file.)

23 Jan 2018

Brendan McDonnell wrote:

Close. I'm not trying to build with mbed compile. I want to export to a project that will build with C++11. I'm currently exporting to NXP MCUXpresso, which uses arm-none-eabi-gcc. Later I plan to export to Visual Studio Code, still using arm-none-eabi-gcc.

I am working with Visual Studio Code and it doesn't matter if you are building with mbed compile or a makefile both are using arm-none-eabi-gcc compiler if you set it up.

If you compile with

mbed compile command with custom profile

mbed compile -m [your board] -t GCC_ARM --profile ./release.json

than you have to change the lines in your custom profile as I mentioned in my first post. I don't know what the exporter generates for "IAR" but if you have a Makefile search for the following line at the "# Tools and Flags" section:

mbed compile command with custom profile

CPP     = 'arm-none-eabi-g++' '-std=gnu++98' ...

and change it to:

mbed compile command with custom profile

CPP     = 'arm-none-eabi-g++' '-std=gnu++11' ...

Brendan McDonnell wrote:

I don't think this profile feature for exports exists.

I copied mbed-os/tools/profiles/release.json to the root of my project folder, and changed "-std=gnu++98" to "-std=gnu++11" in the GCC_ARM section.

Per your suggestion, when I do mbed export profile release -i mcuxpresso, it gives an error. When I use the full filename (mbed export profile release.json -i mcuxpresso, or with the = as mbed export profile=release.json -i mcuxpresso), it completes the export, but it has no effect on the exported project settings. There are still two build configurations (build and release), and both are still set to GNU++98.

It does exists, the mbed-cli is not well documented (i.e. see https://docs.mbed.com/docs/mbed-os-handbook/en/latest/debugging/vscode/), but if you do it your way, the default (original) profile config is used. When I am exporting a project I type:

mbed compile command with custom profile

mbed export -i vscode_gcc_arm -m EFM32PG12_STK3402 --profile release

and the project generates from the default profile, the project files/settings. If you want to use your custom profile then you have to use the absolute or relative path to your custom profile i.e.:

mbed compile command with custom profile

mbed export -i vscode_gcc_arm -m EFM32PG12_STK3402 --profile=./release.json

or

mbed compile command with custom profile

mbed export -i vscode_gcc_arm -m EFM32PG12_STK3402 --profile=path\to\your\config\release.json

I tried it out and the exporter uses the settings from my custom profile and I don't have to touch the Makefile to build with C++11. I personally modify the Makefile anyway but for other reasons, which would blow up this post... :-)

Hope I could help you!

23 Jan 2018

Double post please delete...

13 Feb 2018

I've written the mcuxpresso exporter and had a problem with creating other build configurations as release or debug. These names seem to be hard coded in the eclipse MCUXpresso plugin. The base for this exporter was the gnuarmeclipse, there it works to create additional profiles:

mbed export -m LPC4088 -i gnuarmeclipse --profile mbed-os/tools/profiles/myrelease-c11.json

myrelease-c11.json can be a copy of the standard release profile with your modified settings. You will get the three built-in profiles release, debug and develop plus the user profiler myrelease-c11. Writing the exporter took a lot of time by reverse engeneering the necessary conversions for the ecplipse project file, currently I don't have time to fix this (if it is even possible). Another workaround is to change the mbed-os/tools/profiles/release.json to the required settings.

30 Aug 2018

I would like to lend my vote to adding support for C++11 in the online compiler.

I decided I would like to use mbed for a project rather than rolling my own drivers and so I started a test app using the online compiler to talk to a 3d magnetometer. Around 5 minutes in to using the compiler, I wanted to use a 3dvector to hold the magnetometer readings. No problem. I have a very solid and well tested 3d vector library which has been around for over 15 years, which I have used previously for this purpose and which I could try to import, but guess what? .. I can't use my favourite library with online embed since that library uses C++11. Only way to do it would be to roll my own 3d vector library or go back to a legacy version of my 3d vector library, which isnt going to happen, so this rules out using the online compiler for me. I can use the offline version of Mbed sure, but cant share my code with the community.

C++11 is actually much easier for beginners to use than C++98. The C++11 additional features such as decltype and auto to deduce the type of an expression are features that make code simpler to read and understand. The constexpr feature is also useful to guarantee constness so that more constants can be placed in ROM.

I have read the mbed github issues on this subject and the only reason given for not allowing the switch is that it cant be tested, but clearly it can simply by using the above procedure and pointing the compiler at the test suite.