Build_flags not applied to linker command with AVR toolchain?

Hello,

First a big thank you for platformio, great idea, very good implementation, I use to want to know exactly what toolchain I was using, but now I use platformio …

I have a question regarding the build_flags in the platformio.ini file.

I am using platformio to debug a code with Atmel Studio and an AVR-Dragon, so I need to compile with "build_flags = -g -gdwarf-2"
The setting is correctly applied to the compile commands but it does not seem to apply to the linker command so it is kind of useless …
If I re-run the linker command with the correct flag, then the debugging information is present in AVR Studio.

Here are extracts of platformio run -v for compile and link :

Compile : avr-g++ -o .pioenvs\nanoatmega328\src\X1.6.ino.o -c -fno-exceptions -fno-threadsafe-statics -fpermissive -std=gnu++11 -g -Os -Wall -ffunction-sections -fdata-sections -flto -mmcu=atmega328p -g -gdwarf-2 -DF_CPU=16000000L -DPLATFORMIO=30500 -DARDUINO_ARCH_AVR -DARDUINO_AVR_NANO -DARDUINO=10619 -IC:\Users\user.platformio\packages\framework-arduinoavr\cores\arduino …

Link : avr-g++ -o .pioenvs\nanoatmega328\firmware.elf -Os -mmcu=atmega328p -Wl,–gc-sections -flto -fuse-linker-plugin .pioenvs\nanoatmega328\src… (list of files) -L.pioenvs\nanoatmega328 -Wl,–start-group .pioenvs\nanoatmega328\libFrameworkArduinoVariant.a .pioenvs\nanoatmega328\libFrameworkArduino.a -lm .pioenvs\nanoatmega328\lib\libEEPROM.a .pioenvs\nanoatmega328\lib\libSPI.a .pioenvs\nanoatmega328\lib\libWire.a -Wl,–end-group

I am missing “-g -gdwarf-2” in the linker command …

Is there a hidden “link_flag” setup somewhere or am I missing something ?

Regards

Francois

If you prepend a flag with -Wl, it should get passed to the linker. You can see some examples in the output of the linker you have shown.

Hello,

Like this ?
build_flags = -g -gdwarf-2 -Wl,-g -Wl,-gdwarf-2

This does not work, the linker command line needs to be :

avr-g++ -o .pioenvs\nanoatmega328\firmware.elf -g -gdwarf-2 -Os -mmcu=atmega328p -Wl,–gc-sections -flto …

I think the -Wl, are options for ld, but the debug options are for gcc/gcc++

Regards
Francois

My answer in advanced scripting : Redirecting...