Search code examples
c++gccincludesuppress-warningsgcc-warning

How to eliminate external lib/third party warnings in GCC


In the software project I'm working on, we use certain 3rd party libraries which, sadly, produce annoying gcc warnings. We are striving to clean all code of warnings, and want to enable the treat-warnings-as-errors (-Werror) flag in GCC. Is there a way to make these 3rd party generated warnings, which we cannot fix, to disappear?


Solution

  • I presume you are talking about the warnings coming from the 3rd party library headers.

    The GCC specific solution would be to create another wrapper header file which has essentially the two lines:

    #pragma GCC system_header
    #include "real_3rd_party_header.h"
    

    And use the wrapper instead of the original 3rd party header.

    Check another SO response detailing the pragma. It essentially tells GCC that this (with recursively included files) is a system header, and no warning messages should be generated.

    Otherwise, I'm not aware how one can disable warnings coming from the 3rd party code. Except by the brute force of course: in the build system configure the files to be built with warnings off.