Arduino 1.0.6: How to change compiler flag?

14,003

Solution 1

Using the IDE is very difficult to do that.

I would advise you to go full command line by using Sudar's great Arduino Makefile.

This way you'll be able to customise the compiler flags to your liking.

I've also created the Bare Arduino Project to help you get started. The documentation covers a lot points, from installing the latest avr-gcc toolchain to how to use the repository, compile and upload your code.

If you find something missing, please, feel free to fill an issue on Github so that I can fix it :)

Hope this helps! :)

Solution 2

Add custom compiler flags to platform.local.txt. Just create it in the same directory where platform.txt is. For example:

compiler.c.extra_flags=
compiler.c.elf.extra_flags=
compiler.S.extra_flags=
compiler.cpp.extra_flags=-mcall-prologues -fno-split-wide-types -finline-limit=3 -ffast-math
compiler.ar.extra_flags=
compiler.objcopy.eep.extra_flags=
compiler.elf2hex.extra_flags=

In this example C++ flags will make large sketch smaller. Of course, you can use your own flags instead. Since platform.local.txt does not overwrite standard files and is very short, it is very easy to experiment with compiler flags.

You can save platform.local.txt for each project in its directory. It will NOT have any effect in project's directory, but this way if you decide to work on your old project again you will be able to just copy it to the same directory where platform.txt is (typically ./hardware/arduino/avr/) and continue work on your project with project-specific compiler flags.

Obviously, using Makefile as ladislas suggests is more professional and more convenient if you have multiple projects and do not mind dealing with Makefile. But still, using platform.local.txt is better than messing with platform.txt directly and an easy way to play with compiler flags for people who are already familiar with Arduino IDE.

Solution 3

You can use #pragma inside the *.ino file so as not to have to create the local platforms file:

#pragma GCC diagnostic warning "-fpermissive"
#pragma GCC diagnostic ignored "-Wwrite-strings"

For other ones, see HERE.

Solution 4

Yes, but not in 1.0.6, in 1.5.? the .\Arduino\hardware\arduino\avr\platform.txt specifies the command lines used for compiling.

One can either modify this file directly or copy it to your user .\arduino\hardware... directory to create a custom platform. As not to alter the stock IDE. This will also then exist in other/updated IDEs that you can run. You can copy just the platform file and boards.txt. And have your boards.txt file link to the core: libraries as not to have a one-off. See

Reference: Change CPU speed, Mod New board

Share:
14,003
TheInvisibleFist
Author by

TheInvisibleFist

Updated on July 22, 2022

Comments

  • TheInvisibleFist
    TheInvisibleFist almost 2 years

    I'm currently working on a project using Arduino 1.0.6 IDE and it does not seem to accept C++ 11 std::array. Is it possible to change the compiler flag to make this work?