3

I would like the Arduino IDE to display compiler warnings, and I would rather not have to compile once in the terminal for warnings, and again through Arduino to generate the hex file.

Holding down the shift key while clicking the "Verify" button shows intermediate commands, but none of their output. Is this possible without hacking the Arduino IDE?

1
  • o_O - It doesn't display warnings?!?! A quick Google confirmed that there were complaints about this elsewhere. I found this bug report and patch if you're willing to hack the IDE; it just involves changing -w to -Wall in 2 places. I didn't find solutions that don't involve hacking the IDE. Commented Oct 18, 2011 at 16:30

5 Answers 5

5

Using Arduino IDE 1.6.4 and newer, the warning level can be easily adjusted via menu FilePreferencesCompiler warnings:.

Using Arduino AVR Boards, the compiler flags set via this option are:

Sign up to request clarification or add additional context in comments.

Comments

3

The default compiler command line options include -w, which suppresses warnings, but you can change that by editing C:\Program Files (x86)\Arduino\hardware\arduino\avr\platform.txt. Since the libraries might contain warnings, but I want -Werror for myself, I removed the -w options, and then added to my source code:

#pragma GCC diagnostic error "-Wall"
#pragma GCC diagnostic error "-Werror"

3 Comments

This works great! However, this by itself also introduces a new warning (by a change in some newer version of GCC?): "warning: '-Werror' is not an option that controls warnings [-Wpragmas]. #pragma GCC diagnostic error "-Werror"". This was observed with GCC version 7.3.0 (corresponding to Arduino IDE 1.8.12). This is noise that has to be manually ignored. The closest I have been able to find so far is Compile Warning in GCC 6.3.0 #561. If you find a way to suppress the warning (without suppressing important warnings), can you add it?
Whoa! This is much easier! And also, it aborts compilation so it is never overlooked.
Related: -Werror causes compiler to stop on #warning. What can I do to prevent this? - "the proper way to issue warnings and avoid these additional messages/errors from -Wpedantic is to use #pragma message."
2

This feature has been added to the latest Arduino source code, although is not yet in a released version (see Showing compilation warnings when verbose output is enabled).

It's planned to be included in the next major Arduino IDE release (version 1.0) which is currently planned for release at the end of October 2011. The current release candidate has this fix (as of October 25, 2011).

To enable compiler warnings from within the Arduino IDE, open menu FilePreferences, and then tick Show verbose output during: compilation and/or Show verbose output during: upload.

1 Comment

To have it detect more errors (e.g., accidentally leaving out () from a function call to a function with zero parameters), change option "Compiler warnings" from "Default" to "More" or "All".
1

Most answers here seem to be outdated. From Arduino.app 1.5 onwards you must find the file preferences.txt (https://www.arduino.cc/en/Hacking/Preferences) and change the line compiler.warning_level=none to compiler.warning_level=all IMPORTANT: Quit Arduino first, edit, then start the IDE again.

Comments

1

The feature as described by Matthew, not only displays the warnings, but a lot of distracting information on how the compiler was called as well.

See the addendum to my question Have the Arduino IDE set compiler warnings to error. It implements the changes to the Arduino script:

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

And make the extra/avr-g++:

#! /usr/bin/env python

import os
import sys
import subprocess

checklibpat = [
    'SoftwareSerial',
    'GSM_GPRS',
]

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

cmd = ['avr-g++'] + sys.argv[1:]
os.environ['PATH'] = os.environ['ORGPATH']
fname = sys.argv[-2][:]
extend = False
warn = False
if cmd[-2].startswith('/tmp'):
    extend = True
    warn = True
if not extend:
    for l in checklibpat:
        if l in cmd[-2]:
            warn = True
            break
if warn:
    #print len(fname), list(fname)
    for i, c in enumerate(cmd):
        if c == '-w':
            cmd[i] = wall
            break
    if extend:
        cmd.insert(1, werr)
## to enable deprecated stuff (Print.cpp) with gcc 4.7.0
#cmd.insert(1, '-D__PROG_TYPES_COMPAT__=1')
subprocess.call(cmd)

Comment out extend = True if you do not want the compiler to interpret warnings in your source as errors.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.