让 Arduino IDE 将编译器警告设置为错误 [英] Have the Arduino IDE set compiler warnings to error

查看:31
本文介绍了让 Arduino IDE 将编译器警告设置为错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法将编译器警告设置为在 Arduino IDE 中被解释为错误?
或者任何设置 GCC 编译器选项的通用方法?

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?

我查看了 ~/.arduino/preferences.txt 文件,但我没有发现任何表明微调控制的内容.我还查看了是否可以通过环境变量设置 GCC 选项,但我没有找到任何东西.

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

我不想有冗长的编译器输出(您可以使用 IDE 指定),这会分散太多不必要的信息,我也不想浪费时间阅读它.

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, and I don't want to waste my time on reading through it.

我希望编译在出现警告时停止,以便清理代码.我的偏好是能够设置 -Werror= 选项,但是通用的 -Werror 可以用于 .ino 的小代码大小项目.

I want 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.

附录:

根据所选答案中的建议,我实现了一个 avr-g++ 脚本并将其放在普通 avr-g++ 之前的路径中.为此,我将 Arduino 命令更改如下:

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}"

在 APPSDIR(Arduino 命令所在的位置)的新目录 extra 中,我有一个 avr-g++ 这是一个 Python 脚本:

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)

因此,您将第一个命令替换为原始编译器名称并重置用于不包含 extra 目录的环境.

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

fname 实际上很奇怪.如果打印出来,只有abc.cpp,但它的长度要大得多,实际上以/tmp开头.所以我会检查以决定是否添加/更新编译选项.

The fname is actually strange. If you print it, 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.

推荐答案

看起来您在使用 Linux.Arduino是一个脚本,所以你可以在脚本中设置PATH,将开头的目录包含到包含程序的目录中,avr-g++.那么 Java 的东西应该从那里拿走编译器,不是吗?

It looks like you are on Linux. Arduino is a script, so you can set PATH in the script to include a directory at the beginning to a directory containing a program, avr-g++. Then the Java stuff should take the compiler from there, should it not?

该程序然后调用带有额外选项的普通 /usr/bin/avr-g++.

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

这篇关于让 Arduino IDE 将编译器警告设置为错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆