I am developing Arduino project code for which I have written my own debug macros,
So to test them working or not, I want to see preprocessed code in vs code.
Hi @mrnams,
One way to do it is to pass the -E
flag to the gcc compiler, which as you mentioned Arduino, is what you will be using, at least, the avr version! The option, which must be upper case, tells the compiler driver to stop after running the pre-processor. This can be done in platformio.ini
as follows:
[env:2019]
platform = atmelavr
board = diecimilaatmega328
build_flags = -E
When you compile with verbose mode on, I use the command line and simply pio run -v
but there’s a verbose build option within VSCode also, you will get an error like this:
Building in release mode
avr-g++ -o .pio/build/2019/src/main.o -c -Wno-error=narrowing -fno-exceptions -fno-threadsafe-statics -fpermissive -std=gnu++11 -Os -Wall -ffunction-sections -fdata-sections -flto -mmcu=atmega328p -E -DF_CPU=16000000L -DPLATFORMIO=50101 -DARDUINO_AVR_DUEMILANOVE -Iinclude -Isrc src/main.cpp
avr-g++ -o .pio/build/2019/firmware.elf -Os -mmcu=atmega328p -Wl,--gc-sections -flto -fuse-linker-plugin .pio/build/2019/src/main.o -L.pio/build/2019 -Wl,--start-group -lm -Wl,--end-group
.pio/build/2019/src/main.o: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status
*** [.pio/build/2019/firmware.elf] Error 1
The reason being that the “object” file, .pio/build/2019/src/main.o
is actually ASCII text and is the output from the pre-processor. You can open the file in VSCopde for a look-see as required.
Once happy, don;t forget to revert back the platformio.ini
file to remove that option.
HTH
Cheers,
Norm.
Hey, many thanks, works perfectly.