Arduino 1.0.6: How to change compiler flag?

十年热恋 提交于 2019-12-07 09:20:54

问题


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?


回答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! :)




回答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.




回答3:


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




回答4:


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.




回答5:


I wanted to add the -fpermissive flag Under linux here what I have done with success

The idea is tow replace the two compilers avr-gcc and avr-g++ by two bash scripts in which you add your flags (-fpermissive for me)

With root privilege:

rename the compiler "avr-gcc" (present in /usr/bin) "avr-gcc-real" rename the compiler "avr-g++" (present in /usr/bin) "avr-gcc-g++-real"

Now create to bash scripts avr-gcc and avr-g++ under /usr/bin/

script avr-gcc contains this line: avr-gcc-real -fpermissive $@

script avr-g++ contains this line: avr-g++-real -fpermissive $@

As you may know $@ denotes the whole parameters passed to the script. Thus all the paramaters transmitted by the IDE to compliers are transimitted to your bash scripts replacing them (which call the real compilers with your flags and the IDE one)

Don't forget to add executable property to your scripts: chmod a+x avr-gcc chmod a+x avr-g++

Under windows I don't know if such a solution can be done.



来源:https://stackoverflow.com/questions/28037491/arduino-1-0-6-how-to-change-compiler-flag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!