Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Warning Level for 3rd Party Libs

I generally like to compile against warning level 4 in Visual Studio and treat all warnings as errors. The problem is, Ogre3D is not compiled with warning level 3 (neither is FBX SDK or OIS, which I am also using), and that poses a problem because now I have a ton of warnings from Ogre3D libraries that are now treated as errors. So far I have been compiling at level 3, but that makes me very uneasy. Is there any way to disable warnings for specific 3rd party libraries over which I have no control?

like image 237
Samaursa Avatar asked Oct 18 '10 04:10

Samaursa


People also ask

What are different flags and options with GCC regarding warnings?

You can request many specific warnings with options beginning with ' -W ', for example -Wimplicit to request warnings on implicit declarations. Each of these specific warning options also has a negative form beginning ' -Wno- ' to turn off warnings; for example, -Wno-implicit .

How do you turn off warnings in C++?

To disable a set of warnings for a given piece of code, you have to start with a “push” pre-processor instruction, then with a disabling instruction for each of the warning you want to suppress, and finish with a “pop” pre-processor instruction.

Which option of GCC inhibit all warning messages?

Warn if variadic macros are used in pedantic ISO C90 mode, or the GNU alternate syntax when in pedantic ISO C99 mode. This is default. To inhibit the warning messages, use -Wno-variadic-macros . Warn if a register variable is declared volatile.

What does the werror flag do?

The "-Werror" compiler flag treats all warnings as build errors. By promoting all warnings to errors, it enforces the developers to ensure such build warnings that may otherwise go unnoticed or only loosely concerned about by developers to now treat it with priority given that it will interrupt the build process.


2 Answers

You don't say exactly how you are compiling, but here are some options:

1 - Inside Visual Studio, you can set the warning level for individual source files via the Properties for each source file

2 - You can also change the the warning level dynamically within a file using

#pragma warning(push, 3)
// Some code, perhaps #includes
#pragma warning(pop)

which sets the warning level to 3 between the two pragmas.

like image 139
David Norman Avatar answered Oct 07 '22 22:10

David Norman


It may be that if you disable the most well-known MSVC sillywarnings, the problem will at least become managable.

My sillywarnings suppression header is available at my blog; it's enough to compile code using <windows.h> at warning level 4 with MSVC, with no warnings.

Other than that, you can go to the extreme measure of employing a "compiler firewall", which means putting all direct usage of the 3rd party library within an implementation file or set of such files. Then you can compile those files at low warning level. But I don't think it's worth it.

Cheers & hth.,

like image 33
Cheers and hth. - Alf Avatar answered Oct 07 '22 22:10

Cheers and hth. - Alf