-isystem for MS Visual Studio C++ Compiler

后端 未结 4 1369
花落未央
花落未央 2021-02-20 06:54

I usually like to have a lot of warnings enabled when programming. However, some libraries contains code that easily causes warnings (.., python, Qt, ..). When compiling with gc

4条回答
  •  一个人的身影
    2021-02-20 07:32

    No, MSVC doesn't have an -isystem equivalent.


    look at the output output from cl /? :

    /wd disable warning n

    /we treat warning n as an error

    /wo issue warning n once

    /w set warning level 1-4 for n

    Note that this disables the warnings for your entire project; I remember when using Qt I'd rather change it's main header with the #pragma warning disable and enable at the end again so I could still see all warnings for my own source.

    Edit the author edited his question, updated answer: there is no way to get your code with warnings and Qt code without warnings using compiler flags: how are you going to tell the compiler what is 'your' code?

    Note that the above flags can be applied at file level as well, so this would allow you to disable the warnings for only those files in which you include Qt headers, but that still means you cannot see them for your own code in that files.

    So I stay with the answer above; it is not quite pretty, but I'm pretty sure it's the only way: use #pragma at the beginning and the end of the Qt header(s). Either change the Qt headers (even more ugly), or choose a less invasive way like this:

    //your source/header file
    #include "shutuppqt.h"
    #include 
    #include "enableallwarnings.h"
    

    example "shutuppqt.h"

    #ifdef MSVC
      #pragma warning ( disable : 4222 ) //or whatever warning Qt emits
    #else
      //....
    #endif
    

    example "enableallwarnings.h"

    #ifdef MSVC
      #pragma warning ( enable : 4222 ) //or default instead of enable
    #else
      //....
    #endif
    

提交回复
热议问题