Is there a way to set additional c++ compiler options???

I really would like to be able to add additional c++ compiler options that would do the following:

  1. write a file consisting of the output of the preprocessing stage (i.e. a file containing the source code file with all macros expanded). This is easy enough to do with the -E option if I were to manually execute: gcc -E ....

  2. write a file consisting of the assembler code generated by the compiler. This would allow me to actually see and study, in a meaningful way, what code is actually generated and executed.

I've looked at the Arduino preferences file to see if there exists a flag to enable this behavior but did not find any. Also searching all the arduino related files also did not reveal where the compiler is actually invoked so I could not make any modifications. So, is there a way I can do this or can the Arduino development team add this functionality?

The easiest way to do things like this currently is to use verbose compilation to figure out where it has put your temporary files, and then open a cli window, connect to that directory, and cut&paste the appropriate commands, add your modifications, and run them manually. (using the IDE-preprocessed files that are already built.)

For example, “verifying” Blink on my Mac shows:

/Applications/arduino/Arduino-1.5.2.app/Contents/Resources/Java/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=152 -I/Applications/arduino/Arduino-1.5.2.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino -I/Applications/arduino/Arduino-1.5.2.app/Contents/Resources/Java/hardware/arduino/avr/variants/standard /var/folders/jz/5yb8f2hr8xjcpf0059bsfz4r0000gn/T/build2340544114733970054.tmp/Blink.cpp -o /var/folders/jz/5yb8f2hr8xjcpf0059bsfz4r0000gn/T/build2340544114733970054.tmp/Blink.cpp.o

So I do:

BillW-MacOSX-2<9997> cd /var/folders/jz/5yb8f2hr8xjcpf0059bsfz4r0000gn/T/build2340544114733970054.tmp/

BillW-MacOSX-2<9999> /Applications/arduino/Arduino-1.5.2.app/Contents/Resources/Java/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=152 -I/Applications/arduino/Arduino-1.5.2.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino -I/Applications/arduino/Arduino-1.5.2.app/Contents/Resources/Java/hardware/arduino/avr/variants/standard -E -o blink.E Blink.cpp

BillW-MacOSX-2<10000> /Applications/arduino/Arduino-1.5.2.app/Contents/Resources/Java/hardware/tools/avr/bin/avr-objdump -I. -S Blink.cpp.elf >Blink.S

In the version 1.5.x you can modify the platform.txt file which stores the command lines sent to the compiler and linker.

Mine is located here: D:\arduino-1.5.5-r2\hardware\arduino\avr

platform.txt

Is there a good way to use this feature to make temporary changes like the original poster is requesting?

westfw:

platform.txt

Is there a good way to use this feature to make temporary changes like the original poster is requesting?

Not sure what you mean by “temporary”, but yes you can do quite a lot by modifying the platform.txt file
especially if you also utilize a wrapper script.
In this thread I showed how to create a wrapper script around avr-obcopy to create a
symbol table and extended listing file automatically down in the temporary working directory
every time the code is built.
See this post:

While it can also be done on Windows, I didn’t bother to do that as I don’t use Windows and
it is a bit more work since it involves using a secondary batch file wrapper that sits on top of the shell script
wrapper that sets up the environment and then calls the shell script.
(Windows just doesn’t have many of the useful development tools that *nix operating systems have)

This same type of hook can be used on top of avrdude to download the code through
a h/w debugger like the avr dragon and start up all the gdb hooks and then crank up gdb or ddd so you can
do command-line or GUI-based full source level debugging.
This is the kind of stuff that is easy on *nix platforms but can be quite difficult on Windows.

— bill

Thanks to pYro_65 and westfw for pointing me to the solution by modifying the platform.txt file. This file did not exist in my Arduino 1.0 linux environment but I found it once I upgraded to arduino-1.5.6-r2. I edited the file:

arduino-1.5.6-r2/hardware/arduino/avr/platform.txt

and modified the line:

build.extra_flags=-save-temps

This did the trick. I can now see the .i, *.ii, and *.s files after a compilation. The only unexpected result is that these files are *NOT stored in the regular /tmp/build####/ directory (linux) as I was expecting but, instead, they are stored directly in the arduino-1.56-r2/ directory which is really not the best place for them. Perhaps this is a bug since I upgraded to only a BETA arduino version. If this is a bug I can certainly live with it but I really like being able to examine the code the compiler produces!

Thanks to all of your responses!