Have Arduino IDE set compiler warnings to error

你说的曾经没有我的故事 提交于 2019-12-25 02:24:15

问题


Is there a way to set the compiler warnings to be interpreted as an error in the Arduino IDE?
Or any generic way to set gcc compiler options?

I have looked at the ~/.arduino/preferences.txt but found nothing that indicates fine tuned control. I also looked if I could set gcc options via environment variables, but did not find anything.

I don't want to have verbose compiler output (which you can specify using the IDE) that is way too much distracting non-essential information, I don't want to waste my time on reading through it. What I want is for a compilation to stop on a warning, so code can be cleaned up. My preference would be to be able to set -Werror= options, but a generic -Werror will do for the small code size of .ino projects.

Addendum:

Based on the suggestion in the selected answer, I implemented an avr-g++ script and put that in the path before the normal avr-g++. For that I changed the arduino command as follows:

-export PATH="${APPDIR}/java/bin:${PATH}"
+export ORGPATH="${APPDIR}/java/bin:${PATH}"
+export PATH="${APPDIR}/extra:${ORGPATH}"

and in the new directory extra in the APPSDIR (where the arduino command is located), I have an avr-g++ which is a Python script:

#!/usr/bin/env python

import os
import sys
import subprocess

werr = '-Werror'
wall = '-Wall'

cmd = ['avr-g++'] + sys.argv[1:]
os.environ['PATH'] = os.environ['ORGPATH']
fname = sys.argv[-2][:]
if cmd[-2].startswith('/tmp'):
    #print fname, list(fname) # this looks strange
    for i, c in enumerate(cmd):
        if c == '-w':
            cmd[i] = wall
            break
    cmd.insert(1, werr)
subprocess.call(cmd)

So you replace the first command with the orignal compiler name and reset the environment used to not include the extra directory.

The fname is actually strange, if you print it is only abc.cpp but its length is much larger and it actually starts with /tmp. So I check for that to decide whether to add/update the compile options.


回答1:


Look like you on Linux. arduino is a script, so you can set PATH in the script to include a dir at beginning to a directory containing a program avr-g++. Then the java stuff should take compiler from there, should it not.

That program then calls the normal /usr/bin/avr-g++ with the extra options.

I have not tried myself, let me know if you do if that works.




回答2:


One option you have is to compile your sketches from the command line. Take a look at this makefile.



来源:https://stackoverflow.com/questions/10763676/have-arduino-ide-set-compiler-warnings-to-error

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