How do I turn off warnings when compiling a kernel? - c

I'm trying to compile an android kernel using clang and I'm getting warnings that I don’t care about. For compilation I use the command make -j3 CC=clang O=output, so I cannot just add the -Wno-everything argument as if I were using the command clang file.c. As I understand it, I can disable some warnings by adding #pragma to the file that causes the error. But also I have one strange error that does not reference any file:
warning: unknown warning option '-Wno-vectorizer-no-neon' [-Wunknown-warning-option]
How can I turn off all warnings? Or at least this one.
PS: Sorry for my English.

The solution was to add the -Wno-everything argument to the ARCH_CPPFLAGS parameter in the Makefile.

Related

How to ignore "useless storage class" with gcc using -Werror?

I compile my project with -Werror to make sure all of my code is without recognizable warnings. However my current project has a third-party dependency that has an issue in it which causes a warning - and that warning fails my build because of the -Werror flag.
I want to use the -Werror flag and I don't want to correct the third-party package. Is there a way to ignore this warning?
package.h:126:1: error: useless storage class specifier in empty declaration [-Werror]
};
The line of code that generates the error is a struct definition with a "dangling" typedef.
typedef struct my_data_obj {
char* data;
uint32_t data_size;
};
This is obviously a mistake - but I can't find any pragma or any such mechanic to ignore the warning generated from that header file. Any ideas?
EDIT: SOLUTION
Though I'm accepting Florian Weimer's answer because it answers the question most closely it's not the actual fix I settled with. I'll describe that bellow. By including the headers as system headers I did exactly what I wanted to do - suppress the error without having to fix the package.
What I finally did was create a patch file and simply apply that patch each time the project is built.
vim package.h
# fix the file
git add package.h
git diff --cached > package.h.patch
# on build time
git apply package.h.patch
I assume that you want to include package.h from files where you want to enable -Werror.
GCC does not have a separate flag to control this warning, otherwise the compiler would have printed it. With the separate flag, you could have used #pragma GCC diagnostics ignore, as indicated in the other answers, possibly with a wrapper header file.
However, you could put the header file into a separate directory, and instead of using -I to add it to the include path, use -isystem. As a result, the header file is treated as a system header, and unless you also compile with -Wsystem-headers, warnings in system headers are suppressed.
All warnings and errors have specific names, and can be enabled or disabled on a per-warning/-error basis.
For example lets say I have an unused variable and enabled warnings about it, then I will get a message similar to
/some/path/main.cpp:18:9: warning: unused variable ‘i’ [-Wunused-variable]
That last part of the message, the one inside the square brackets, is the name of the specific warning.
With this name you can then disable warnings using the -Wno-<name of warning> option. In the case of the above warning it's disabled with -Wno-unused-variable.
Your use-case is a little different in that you want to disable a warning turned into an error. This is very similar to the above, but the general form of the option is -Wno-error=<name of warning or error>. In our example case it's -Wno-error=unused-variable.
All of this is of course in the GCC documentation, more specifically in the warning options documentation.
So what you have to do is figure out the name of the warning, so you can use it for the -Wno-error= option.

Wrong compiler options accepted via Batch when compiling c code using Hightec compiler

I'm trying to compiler c code using Hightec compiler under win7 64bit operating system. Here is my sample Batch code for compiling:
Root\HightecInstall\bin\ppc-vle-gcc -fno-inline -c -o sample.o sample.c
This is only a sample code with the compiler options "-fno-inline". After I run the batch file, I got an error saying "unknown compiler options -no-inline". But what I input is "-fno-inline". So there is a missing letter "f". I have tried with other options and the output always gave me "unknown compiler options ***" which misses one or two letter at the beginning. For example. -DDefault -> unknown -efault. I don't really understand how that could happen and how could the compiler discard the first one or two letters. Does anyone have some suggestions? Thanks.
Bo

Why do I get a include <windows.h> error when developing on a Windows machine in C?

I am new to C and I am trying to compile a code that uses am external library. Therefore, I am following these steps for linking a library. But at the very first one
gcc -c -Wall -Werror -fpic PICASO_SERIAL_4DLIBRARY.C
I get this
PICASO_SERIAL_4DLIBRARY.C:1:0: error: -fpic ignored for target (all code is position independent) [-Werror]
#include <windows.h>
cc1plus.exe: all warning being treated as errors
additionally undder # there is a arrow above. I tried googling it but I could only find out that this is a Linux problem and not a Windows one (I am developing on Windows now) and the I followed these steps to install gcc. an compiling other small projects work, too.
Anyone any idea, why this doesn't work?
The mention of #include <windows.h> is incidental. That just happens to be the first line of code.
The compiler tries to associate a line of code with the error to help you find the problem. But in this case the code is irrelevant. The error is in the command line and you will get a failure no matter what the code is. But because the compiler is coded to always associate a line of code with an error, it decides, arbitrarily, to point the finger at the first line of code.
Because you use -Werror, warnings are treated as errors. The compiler therefore converts a warning about an ignored option to emit position independent code into an error. The error message states this very clearly:
PICASO_SERIAL_4DLIBRARY.C:1:0: error: -fpic ignored for target (all code is position independent) [-Werror]
I suspect you glazed over when reading the error message, and turned your attention to the line of code that was highlighted. Always read error messages carefully!
To resolve the error, remove the -fpic option from your command line.
Try to compile without -fpic. This flag is inappropriate for the mingw-w64 target.

how to disable gcc warning "cc1: warning: command line option ‘-std=c++11’ is valid for C++/ObjC++ but not for C [enabled by default]"

I am new to cmake and gcc.
The first assignment in my new role in the company was to clean the errors from our linux compilation
I did most of it, and now the only warning I see is
cc1: warning: command line option ‘-std=c++11’ is valid for C++/ObjC++ but not for C [enabled by default]
I want wither to suppress the warning or to solve the issue in the cmake file.
Unfortunately, I still haven't found the correct -Wno-xxx statement that fits here.
Thanks!
Code issue warnings can be silenced with -Wno-xxx options because sometimes you don't have control over the source code. But a warning telling you that a command-line option is incorrect cannot be silenced with yet another command-line option — if you can affect compiler invocation, then why not just remove the incorrect option?
This particular warning tells you that you cannot set standard to C++11 when compiling C code. To get rid of it, find where -std=c++11 is defined in the build configuration, and make sure it is only applied to C++ compilation, and not for C. For example, move it from CFLAGS to CXXFLAGS, or cmake's equivalent thereof.

Errors while compiling Neko VM OS X

I'm trying to compile the Neko VM on Mac OS X (10.5.7) using GCC 4.01 and I'm completely stuck, because it stops while compiling saying:
vm/threads.c:202: error: conflicting types for 'neko_thread_register'
vm/neko_vm.h:37: error: previous declaration of 'neko_thread_register' was here
I've tried googling this and some say it's because of lack of a "prototype" and some say it's because of a header include being done several times, and I can't really find any of those.
The affected line in threads.c:202 looks like this:
EXTERN bool neko_thread_register( bool t ) {
And the affected line in neko_vm.h:37 looks like this:
EXTERN bool neko_thread_register( bool t );
I can't see any difference in them, besides one of them being the implementation of the other.
The compiler command I'm using is:
cc -Wall -O3 -v -fPIC -fomit-frame-pointer -I vm -D_GNU_SOURCE -arch i386 -L/usr/local/lib -L/opt/local/lib -I/opt/local/include -o vm/threads.o -c vm/threads.c
I'd appreciate some ideas on what i might be able to do here, I don't really know where to go from here.
A mirror of the code for Neko which I'm trying to compile can be found here.
Thanks!
Have you tried compiling that file alone and outputting the preprocessed version? It could be that the scope or linkage macros are being modified somewhere in between the header file and the implementation file-- the same could be true of the 'bool' type, which is usually a macro defined by a system header.
According to the GCC 4.2 docs here, you should need to add the -E flag to the compilation line above, and you ought to change -o vm/threads.o to -o vm/threads.i so a file with the correct extension is created (.i means 'preprocessed file', essentially).
First, make sure you compile this as C, not C++.
Second, without seeing the code, it's pretty much impossible to say what the problem is.
But reading the error messages is often helpful (even before you google them):
Apparently neko_thread_register is declared twice, once in threads.c:202 and once in neko_vm.h:37, and the two declarations have different (conflicting) types. So look at the two declarations. If you can't see a problem with them, show us some code.
At the very least, seeing those two lines of code would be necessary. Most likely, the types are typedefs or macros or something similar, and then we'd need to see where they are defined as well.
Without seeing the code, all we can do is repeat the compiler error. "neko_thread_register has two conflicting definitions, at the lines specified."
Did you uncomment this line:
# For OSX
#
# MACOSX = 1 <-- this one
In the makefile?

Resources