platformio / builder-framework-mbed

ARM mbed build script for PlatformIO Build System
http://platformio.org/frameworks/mbed
Apache License 2.0
4 stars 17 forks source link

Configuration of mbed about changing gcc/g++ compiler standard. #20

Closed EthanGuo1995 closed 4 years ago

EthanGuo1995 commented 4 years ago

Q: In my project, I wanna change the default g++ standard(g++14) into another one: c++17.

My platformio.ini file shown as follows:

platform      = nxpimxrt
board         = mimxrt1050_evk
framework     = mbed
debug_tool    = jlink
upload_protocol = jlink
build_unflags = -std=c++14
build_flags       = ${common.build_flags} -std=c++17 -std=gnu++11 -Wexpansion-to-defined

But it did not work, showing "cStandard": "c11", "cppStandard": "c++14" in .vscode\c_cpp_properties.json fie as well, and the warning message lilke "warning: this use of "defined" may not be portable [-Wexpansion-to-defined]" .

With my poor knowlege about gcc compiler and stuff... I wonder what the issue caused this warning. GCC compiler version maybe??

valeros commented 4 years ago

Hi @EthanGuo1995 ! I see here two possible issues:

EthanGuo1995 commented 4 years ago

Hi @EthanGuo1995 ! I see here two possible issues:

  • build_unflags = -std=c++14 looks like you've disabled a wrong standard flag, it should be build_unflags = -std=gnu++14
  • build_flags = ... -std=c++17 -std=gnu++11 ... you've specified two different standards, the compiler will use the latter one. If you need C++17 specify only -std=c++17 or if you need C++17 with GNU extensions then -std=gnu++17

It works!!! Thanks a lot.