EmbDev.net

Forum: ARM programming with GCC/GNU tools How can I tell gcc to not treat warnings as errors ?


von Joe P. (jpepe)


Rate this post
useful
not useful
Hello,

I'm using the Eclipse  Yagarto  gcc toolchain to build a target,
and generate a .bin file for a AT91SAM7X256-EK (evaluation board).


The following is the console output dialogue:

make -C nutapp/httpd USE_UROM=yes USE_MMC=yes all
make: Entering directory `/cygdrive/c/SAM Studio
0.2/workspace/NutOS/nutapp/httpd'

make -C ../.././nutbld/lib/.. install
make[1]: Entering directory `/cygdrive/c/SAM Studio
0.2/workspace/NutOS/nutbld'

make -C arch install
make[2]: Entering directory `/cygdrive/c/SAM Studio
0.2/workspace/NutOS/nutbld/arch'

arm-elf-gcc -MD -c -mcpu=arm7tdmi -Os -mthumb-interwork
-fomit-frame-pointer -Wall -Werror -Wstrict-prototypes
-Wa,-ahlms=arm/dev/ostimer_at91.lst  -DUSE_UROM -DUSE_MMC -DAT91SAM7X_EK
-DAT91SAM7X_EK   -I../.././nutbld/include  -I../.././nut/include
-I'C:\SAM Studio 0.2\workspace/../yagarto/arm-elf/include' -I'C:\SAM
Studio 0.2\workspace/../yagarto/lib/gcc/arm-elf/4.1.1/include'
../.././nut/arch/arm/dev/ostimer_at91.c -o arm/dev/ostimer_at91.o

cc1.exe: warnings being treated as errors

../.././nut/arch/arm/dev/ostimer_at91.c:246: warning: 'At91GetPllClock'
defined but not used

make[2]: *** [arm/dev/ostimer_at91.o] Error 1
make[2]: Leaving directory `/cygdrive/c/SAM Studio
0.2/workspace/NutOS/nutbld/arch'

make[1]: *** [install] Error 2
make[1]: Leaving directory `/cygdrive/c/SAM Studio
0.2/workspace/NutOS/nutbld'
make: Leaving directory `/cygdrive/c/SAM Studio
0.2/workspace/NutOS/nutapp/httpd'

make: *** [MAKE_LIBS] Error 2

Can anyone tell me how to turn off the 'warnings being treated as
errors' option ?

Thanks,
Joe

von Clifford S. (clifford)


Rate this post
useful
not useful
Joe Pep wrote:
> Can anyone tell me how to turn off the 'warnings being treated as
> errors' option ?
Remove the -Werror option.

Or better, just fix the warnings! The warning you have may be benign
(although At91GetPllClock will unnecessarily add to the size of your
code), but warnings are usually either errors or poor coding practice -
an error waiting to happen.

There are many less brutal methods of fixing this one warning (not least
simply removing the unused code!)

The warning is switched on by the use of -Wall, so you could also remove
that and still retain the -Werror; but you will suppress a number of
useful warning types. Rather than using -Wall, you could switch on
individual warning options. See
http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Warning-Options.html#Warning-Options
for details of the warning options and which ones -Wall switches on.

You can suppress the "unused" warning for variables (but not functions)
by using an 'unused' attribute.
(http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Variable-Attributes.html#Variable-Attributes)

If for some reason you want the At91GetPllClock code to remain but are
not using it for the moment, you could wrap it in conditional
compilation:

#if defined USE_AT91GETPLLCLOCK
int At91GetPllClock()
{
...
}
#endif

and then use a -DUSE_AT91GETPLLCLOCK option when you need the code.

Another way of 'fixing' the warning is to make a dummy reference. In the
case of a function, (I assume from its name At91GetPllClock is a
function), this requires care because you don't want to call the
function and you don't want the optimizer to warn of unreachable code,
so:

int main()
{
    volatile dummy = 0 ;
    if( dummy )
    {
        At91GetPllClock() ;
    }

    ....
}

The code above will create a reference that is never called, but the
volatile declaration stops the optimizer from determining that it can
never be called. This has the advantage that the dummy code need not be
removed if you later add a real reference to At91GetPllClock.

One final way of avoiding this warning is to place At91GetPllClock in a
static library and link to that. The linker will only add the code to
your program if it is explicitly referenced, but it is still available
at any time. You could also place At91GetPllClock in a separate module
and simply not use it in this build.

Clifford

von Joe P. (jpepe)


Rate this post
useful
not useful
Thanks much, Clifford.

I hope one day to be 1/2 as well versed as you obviously are with gcc
and all its features and options.
I had already 'used' the function 'At91GetPllClock' by making a dummy
call to it
and did get full compilation, but you've given some good insight for
other alternatives. The pointer to the gcc help pages is also much
appreciated.

Thanks again.

Joe


Clifford Slocombe wrote:
> Joe Pep wrote:
>> Can anyone tell me how to turn off the 'warnings being treated as
>> errors' option ?
> Remove the -Werror option.
>
> Or better, just fix the warnings! The warning you have may be benign
> (although At91GetPllClock will unnecessarily add to the size of your
> code), but warnings are usually either errors or poor coding practice -
> an error waiting to happen.
>
> There are many less brutal methods of fixing this one warning (not least
> simply removing the unused code!)
>
> The warning is switched on by the use of -Wall, so you could also remove
> that and still retain the -Werror; but you will suppress a number of
> useful warning types. Rather than using -Wall, you could switch on
> individual warning options. See
> http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Warning-Options.html#Warning-Options
> for details of the warning options and which ones -Wall switches on.
>
> You can suppress the "unused" warning for variables (but not functions)
> by using an 'unused' attribute.
> 
(http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Variable-Attributes.html#Variable-Attributes)
>
> If for some reason you want the At91GetPllClock code to remain but are
> not using it for the moment, you could wrap it in conditional
> compilation:
>
> #if defined USE_AT91GETPLLCLOCK
> int At91GetPllClock()
> {
> ...
> }
> #endif
>
> and then use a -DUSE_AT91GETPLLCLOCK option when you need the code.
>
> Another way of 'fixing' the warning is to make a dummy reference. In the
> case of a function, (I assume from its name At91GetPllClock is a
> function), this requires care because you don't want to call the
> function and you don't want the optimizer to warn of unreachable code,
> so:
>
> int main()
> {
>     volatile dummy = 0 ;
>     if( dummy )
>     {
>         At91GetPllClock() ;
>     }
>
>     ....
> }
>
> The code above will create a reference that is never called, but the
> volatile declaration stops the optimizer from determining that it can
> never be called. This has the advantage that the dummy code need not be
> removed if you later add a real reference to At91GetPllClock.
>
> One final way of avoiding this warning is to place At91GetPllClock in a
> static library and link to that. The linker will only add the code to
> your program if it is explicitly referenced, but it is still available
> at any time. You could also place At91GetPllClock in a separate module
> and simply not use it in this build.
>
> Clifford

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.