Hello, I am using the CLI compiler to compile a program for a microcontroller.
It is all working fine at the moment. My code has a number of warnings in it, which could could be fixed but I choose to ignore them as my code works and fixing the warnings will use up space in the microcontroller which is already at a premium.
My issue is now when there is an error in my code, the errors are listed first, followed by the warnings - the warning push all the errors off the top of the console and I cannot see them.
Attempting to redirect the output via a '| more' or ' >> OutputFile' do not seem to work.
Is there any way to supress the warnings from the compiler and only show the errors please?
I have tried adding "--warnings none" to the compiler command line, but it does not seem to have any effect.
(Apologies I cannot find a category for the CLI compiler)
This is unusual, but each boards platform author has the freedom to configure the compilation commands according to their own preferences. Even though it is a common convention to add the -w flag to disable all compiler warnings when the warnings level is set to "none", there is nothing in the Arduino platform framework that enforces that on the platform authors.
What is the FQBN you are using in your arduino-cli compile command (as set by the -b or --fqbn flag of the command). If this is a board from a 3rd party boards platform that requires a package index URL to allow the arduino-cli core install command, please also provide that URL.
No worries. There is a specific forum category for the Arduino command line tools such as Arduino CLI:
This is may be a bit of a tangent, but I have found that addressing warnings frequently leads to cleaner code which is likely to be better optimisable by a compiler.
My advice would be to increase the number of warnings (e.g., -Wall -Wextra -pedantic) instead of ignoring them.
I understand usual practice is to address warnings, but if I deal with them it is increasing my code footprint which is already getting close to the space constraints of my microcontroller.
This means that the -Wall flag is added to the compilation command even when you set warnings to "none".
I see the change was made here:
I would like an impactful decision like this to be clearly documented in the commit history, but my experience is that developers (in general, not singling out this project in specific) frequently toss significant changes into a codebase along with unrelated or only vaguely related changes without bothering to document it at all. The reasons for the change are clear in thier mind at the time, so they don't think about spending the time to communicate that to others (which often includes themself some years in the future when they have forgotten the reason for the change).
So it is not clear to me whether this was an intentional change, or maybe something that was intended to be a temporary change during the development of the other changes and accidentally committed to the repository. You could submit an issue to the megaTinyCore repository if you like:
Workaround
I will describe two alternative workarounds you can use to immediately suppress the warnings.
You can pick whichever of them is most convenient to you:
Suppress warnings via --build-property command line flags
It is possible to bypass the normal --warnings mechanism for controling warning level and instead inject the -w flag into the compilation commands via a different mechanism. The --build-property flag allows setting arbitrary build properties from the arduino-cli compile command:
# Overridden by platform.local.txt if used
compiler.c.extra_flags=
compiler.c.elf.extra_flags=
compiler.S.extra_flags=
compiler.cpp.extra_flags=
compiler.ar.extra_flags=
compiler.objcopy.eep.extra_flags=
compiler.elf2hex.extra_flags=
So if you want to suppress compiler warnings for C++ code (files with .ino and .cpp file extensions), then you would add this flag to your arduino-cli compile command:
--build-property "compiler.cpp.extra_flags=-w"
Since the majority of Arduino code is C++, that may be sufficient, but if you are also getting warnings from C code (files with .c extensions) then you can add this flag as well;
--build-property "compiler.c.extra_flags=-w"
Suppress warnings via a platform configuration patch
If you find it too cumbersome to add these flags to the arduino-cli compile commands, There is an alternative solution of patching the megaTinyCore platform configuration:
Compile any sketch for a megaTinyCore board.
After the compilation finishes, take note of the path of the platform shown in the output.
For example:
Used platform Version Path
megaTinyCore:megaavr 2.6.4 /home/per/.arduino15/packages/megaTinyCore/hardware/megaavr/2.6.4
Create a file named platform.local.txt under that path.
Open the platform.local.txt file in any text editor.
Add the following line to the file:
compiler.warning_flags.none=-w
Save the file.
Note that this patch will be lost every time you update to a new version of the megaTinyCore boards platform. So you might want to save a copy of the platform.local.txt file in a safe location so you can quickly copy it back in to the new platform installation folder after each update.
Thanks ever so much for you well detailed response, I wasn't aware the individual libraries could make such changes to the compileing process.
I will raise the issue with the library author.
I have gone with your suggestion to add '--build-property "compiler.c.extra_flags=-w"'
To my compile alias and this works great - I now get a cleaner report with errors only - exactly what I needed.
When I was reading the documentation I thought such a change be possible, but it would have been a long time before I had any chance of figuring it out for myself - if ever.
You are welcome. I'm glad the --build-property workaround is working for you. Nice trick setting up an alias for the compilation command!
The Arduino boards platform system is quite powerful and flexible. In case you happen to be interested in learning more boring details about it, you can find them here in the Arduino Platform Specification: