Language specific build flags?

Hi,

I’d like to apply -Wno-volatile to the build_flags to suppress the many warnings introduced in C++20 for compound assignment, however doing so then produces a warning for every C file that is compiled:

cc1: warning: command-line option ‘-Wno-volatile’ is valid for C++/ObjC++ but not for C

Is there any mechanism for providing language specific options?

1 Like

Use Advanced Scripting to modify the appropriate environment’s construction variables, such as CFLAGS (C only), CCFLAGS (C and C++) or CXXFLAGS.

1 Like

Actually, this is exactly the reference example:

https://docs.platformio.org/en/latest/scripting/examples/split_build_flags.html

Many thanks Max, I’ll take a look

i have the same issue, resolved as shown here: DnWiFiDoorLock/scripts/pio_post_extra_script.py at 29d08cef04a1d6ba48cdca443e7e41c17e2bcf80 · MacDada/DnWiFiDoorLock · GitHub

# pio_extra_script.py

Import("env")
env.Append(CXXFLAGS=['-Wno-volatile'])

Strangely this didn’t work for me initially with the esp32-C3 framework 5.0.2. After some experimentation I found I had to use the ‘pre:’ syntax when specifying the script.

in platformio.ini:

[env:espC3]
extra_scripts = pre:cpp_flags.py

cpp_flags.py:

Import("env")

print("JBK FLAG SCRIPT")

print("JBK BEFORE")

print(env.get('CXXFLAGS'))

# General options that are passed to the C++ compiler

env.Append(CXXFLAGS=["-Wno-volatile"])

print("JBK AFTER")

print(env.get('CXXFLAGS'))

Build output:

JBK FLAG SCRIPT
JBK BEFORE

JBK AFTER
-Wno-volatile
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32-c3-devkitm-1.html
PLATFORM: Espressif 32 (6.3.2) > Espressif ESP32-C3-DevKitM-1
HARDWARE: ESP32C3 160MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-builtin, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-espidf @ 3.50002.230601 (5.0.2) 
 - tool-cmake @ 3.16.4 
 - tool-esptoolpy @ 1.40501.0 (4.5.1) 
 - tool-ninja @ 1.7.1 
 - toolchain-esp32ulp @ 1.23500.220830 (2.35.0) 
 - toolchain-riscv32-esp @ 11.2.0+2022r1
Warning: the 'src_filter' option cannot be used with ESP-IDF. Select source files to build in the project CMakeLists.txt file.

Reading CMake configuration...
...
Building in release mode
riscv32-esp-elf-g++ -o .pio/build/espC3/lib373/CRSF/CRSF.o -c -Wno-volatile -Wall -Werror=all...

Running with the default or the ‘post:’ prefix I see an initial CXXFLAGS that corresponds with the options in the verbose build output, the additional flag appears in the ‘AFTER’ output, but isn’t picked up in the compile line. Using ‘pre:’ solves the problem but I thought it might be worth mentioning in case anyone else hits the problem.