Blackpill with c++17 failed

I tried to use c++17 or gnu++17 for my stm32F411CE project. I set up the following flags in the"platformio.ini" file and found out that the “auto-generated” “c_cpp_properties.json” still contains “Standard”: “C11” and “cppStandard”: “c++14”. I have searched around and tried different settings with the same result. Could someone help me with this? If I manually change the corresponding settings in the c_cpp_properties.json to “cppStandard”: “c++17”, the program compiles without warning. I really appreciate any help you can provide.

build_unflags = -std=c++14
build_flags = -std=gnu++17

So even though you set this and regenerate the intellisense (Ctrl+Shift+P → Rebuild Intellisense) the .vscode/c_cpp_properties.json still shows C++14?

I just tried again as you instructed. .vscode/c_cpp_properties.json still shows C++14. Below is part of my platformio.ini file and the generated c_cpp_properties.json file.

platformio.ini
[platformio]
default_envs = blackpill_f411ce

[env]
platform = ststm32
board = blackpill_f411ce
framework = arduino
build_unflags = -std=c++14
build_flags = -std=gnu++17

[env:blackpill_f411ce]
build_flags = -D DEBUG
debug_build_flags = -Og -ggdb3 -g3

c_cpp_properties.json

        "cStandard": "c11",
        "cppStandard": "c++14",

Oh yeah of course. Because looking at the Advanced->Verbose Build task, the default invocation is

arm-none-eabi-g++ -o .pio\build\blackpill_f411ce\src\main.cpp.o -c -std=gnu++14

so you have to unflag gnu++14, not c++14.

I just unflag gnu++14 instead of c++14. The funny thing is that the generated c_cpp_perperties.json file still contain “cStandard”: “c11” and “cppStandard”: “c++14” entry simply disappears even though I did specify gnu++17 as below:

[env]
platform = ststm32
board = blackpill_f411ce
framework = arduino
build_unflags = -std=gnu++14
build_flags = -std=gnu++17

Hmm that’s not what I’m getting…

1 Like

I moved all settings down from [env] section to [env:blackpill_f411ce] section and it works as you had illustrated…I thought [env:blackpill_f411ce] ‘inherits’ settings from [env], doesn’t it? At least now it works. Thanks…

My bad, I didn’t spot the glaring error you made in your original platformio.ini. When you have

[env]
platform = ststm32
board = blackpill_f411ce
framework = arduino
build_unflags = -std=c++14
build_flags = -std=gnu++17

[env:blackpill_f411ce]
build_flags = -D DEBUG
debug_build_flags = -Og -ggdb3 -g3

the two build_flags do not add up. One will overwrite the other.

You must explicitly interpolate the values per documentation

https://docs.platformio.org/en/latest/projectconf/interpolation.html

meaning you could write

[env]
platform = ststm32
board = blackpill_f411ce
framework = arduino
build_unflags = -std=gnu++14
build_flags = -std=gnu++17

[env:blackpill_f411ce]
build_flags = ${env.build_flags} -D DEBUG
debug_build_flags = -Og -ggdb3 -g3
2 Likes

I see…I guess I did not read the document carefully…thank you for pointing it out.