[SOLVED] Is there any way to attach -D from within arduino IDE

I am trying to attach a -Ddisable_simple_fns option to the compiler command that arduino IDE generates automatically. Is there a way to do it? Thanks. It would be nice to have this hack "custom def" in arduino IDE although I don't know how to.

[Edit]: The solution appears to require either visual studio plugin or arduino 1.5 and creating new board def in boards.txt with a "board_name.build.extra_flags=-Dsomething=value".

I believe IDE 1.5 reads the command-lines from platform.txt.

Edit: Remove plural.

Thanks. I will put IDE upgrade on my agenda once I'm done with work at hand. I am using 1.0 right now.

Hey, i'm using 1.5.1r2 I cannot find a 'platforms.txt',
I also had a browse through the IDE preferences ( C:\Users\Chris\AppData\Roaming\Arduino ) but no luck. Would be very nice if I could change the optimisation levels.

Any locations I should be looking in?

EDIT: windows search is blind ( the machine's fault not the user :stuck_out_tongue: ), it was in "D:\arduino-1.5.1r2\hardware\arduino\avr"

Sorry about that. The filename is platform.txt (singular; not plural).

It's in the exeFolder/hardware/arduino/avr and can work in conjunction with the new properties in the 1.5 boards.txt

Alternatively if you want it to work with 1.0.x formats then the visual studio plugin allows any number of -D defines via the project property "Defines - Project"

But 1.5 might be the simplest route unless you also want intellisense etc and are using windows.

Where do I get this visual studio plugin?

Download via the main site here

You need a copy of Visual Studio Pro. This page shows how to get a copy for free

If you have any questions or want the serial debugger upgrade then register for the forum

Is it only possible to modify boards.txt to add another def in 1.5?

Thanks for the visual studio link.

I've only recently started with 1.5 so can't recall exactly but I think you can add your own overrides and "recipe" patterns directly to the boards.txt. You will find the default settings and recipe patterns in the platform.txt. Example:-

recipe.cpp.o.pattern=

So this would mean you could copy a board def in the boards.txt, change the name to whatever you want and add your own recipe specifically for your new board definition. This would allow you to optionally invoke your additional compiler defines just by switching board. (I hope this info is correct)

If you have vs installed then it is certainly easier to achieve this with the vs plugin, which also allows us to set a -D list on a per configuration basis. This means, for example, that we can have a -D list for "My Normal Compile" and a list for "My Special Compile" etc.

EDIT: How to copy a board def - Example

Below is the def for the Uno

##############################################################

uno.name=Arduino Uno
uno.upload.tool=avrdude
uno.upload.protocol=arduino
uno.upload.maximum_size=32256
uno.upload.speed=115200

uno.bootloader.tool=avrdude
uno.bootloader.low_fuses=0xFF
uno.bootloader.high_fuses=0xDE
uno.bootloader.extended_fuses=0x05
uno.bootloader.unlock_bits=0x3F
uno.bootloader.lock_bits=0x0F
uno.bootloader.file=optiboot/optiboot_atmega328.hex

uno.build.mcu=atmega328p
uno.build.f_cpu=16000000L
uno.build.core=arduino
uno.build.variant=standard

Below is a duplicate called Arduino Uno 2. Notice that each property for the board starts with a unique id, in this case "uno2". So to copy a def you only need to set the .name property and ensure that each entry starts with a unique id of your choice.

##############################################################

uno2.name=Arduino Uno 2
uno2.upload.tool=avrdude
uno2.upload.protocol=arduino
uno2.upload.maximum_size=32256
uno2.upload.speed=115200

uno2.bootloader.tool=avrdude
uno2.bootloader.low_fuses=0xFF
uno2.bootloader.high_fuses=0xDE
uno2.bootloader.extended_fuses=0x05
uno2.bootloader.unlock_bits=0x3F
uno2.bootloader.lock_bits=0x0F
uno2.bootloader.file=optiboot/optiboot_atmega328.hex

uno2.build.mcu=atmega328p
uno2.build.f_cpu=16000000L
uno2.build.core=arduino
uno2.build.variant=standard

Thanks. I added a new line phi_panel.build.extra_flags=-Ddisable_simple_fns to a new board def I copied and changed and it did the trick, according to the verbose output. I wonder if I can do phi_panel.build.extra_flags=-DXX=10 with the defined number instead of just defining a name. Will try later.

##############################################################

phi_panel.name=Phi panel
phi_panel.upload.tool=avrdude
phi_panel.upload.protocol=arduino
phi_panel.upload.maximum_size=32256
phi_panel.upload.speed=115200

phi_panel.bootloader.tool=avrdude
phi_panel.bootloader.low_fuses=0xFF
phi_panel.bootloader.high_fuses=0xDE
phi_panel.bootloader.extended_fuses=0x05
phi_panel.bootloader.unlock_bits=0x3F
phi_panel.bootloader.lock_bits=0x0F
phi_panel.bootloader.file=optiboot/optiboot_atmega328.hex

phi_panel.build.mcu=atmega328p
phi_panel.build.f_cpu=16000000L
phi_panel.build.core=arduino
phi_panel.build.variant=standard
phi_panel.build.extra_flags=-Ddisable_simple_fns

## recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -mmcu={build.mcu} -Ddisable_simple_fns -DF_CPU={build.f_cpu} -D{software}={runtime.ide.version} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"

Great. I don't see why you can't do that. The extra flags are just passed to the compile statement without change, so should work fine.

Yep, everything I typed in there gets appended to the compiler options. Thanks for helping me through! Karma for you!