2

I'm working on a C++ project that uses OpenCV and Boost. Unfortunately when compiling, my compiler gives me hundreds of warnings from the include files of those libraries. Even with an empty main function and no other code I still get these warnings from the include statements. I've heard this is a problem with other 3rd party libraries like Qt. All great libraries. How can I suppress all 3rd party warnings in MSVC.

I know about these solutions:

I've spend hours on these last 2 solutions but without any success. The "broken warnings theory" blog doesn't explain how to apply its solution very well anyway.

I'm using:

  • Visual Studio 2015 and 2019.
  • Boost 1.72
  • OpenCV4

I really appreciate anyone willing to help resolve this issue with me. It would be nice to know who has even solved this issue. So many companies use these libraries, some probably with MSVC. There's no way they just keep with the warnings there and forget about them. I'm at the point where I will pay money to get this resolved. Getting this to work may be the deciding factor between reusing 3rd party libraries and rewriting code myself.

IronMan
  • 51
  • 11
  • *Even with an empty main function and no other code I still get these warnings from the include statements.* -- Which includes give you warnings with an empty main? I can't quite believe that. – DevSolar Sep 08 '20 at 09:48
  • Which MSVC warning level are you targeting? – Bathsheba Sep 08 '20 at 09:48
  • 1
    Where did you find that pragma push only works for your own headers? – Botje Sep 08 '20 at 09:49
  • *There's no way they just keep with the warnings there and forget about them. I'm at the point where I will pay money to get this resolved.* -- You'd have to start with giving a reproducible example of what warnings you're talking about... – DevSolar Sep 08 '20 at 10:59
  • Here's a simple example of my code: #include int main() { boost::asio::io_context context; return 0; } – IronMan Sep 10 '20 at 02:43
  • Here's 1 of the 51 warnings: Severity Code Description Project Path File Line Warning C26495 Variable 'boost::asio::detail::thread_info_base::reusable_memory_' is uninitialized. Always initialize a member variable (type.6). SuppressingBoostWarnings D:\code\libraries\Boost\boost_1_72_0\include\boost\asio\detail D:\code\libraries\Boost\boost_1_72_0\include\boost\asio\detail\thread_info_base.hpp 47 – IronMan Sep 10 '20 at 02:48
  • Note that that warning is an analyzer warning and not covered by the experimental switch in my answer. The general tone of the blog post I linked would "expect" you to submit patches to all external libraries you use to fix these warnings. An expectation which I find very otherworldly, if not plain rude. – rubenvb Sep 10 '20 at 07:12
  • I apologize I meant no offense. – IronMan Sep 11 '20 at 13:53

1 Answers1

1

All this is from this blog post: https://devblogs.microsoft.com/cppblog/broken-warnings-theory/. The general tone of the introduction of the article speaks volumes about why this option wasn't there to begin with (and none of it makes much sense to me).

Basically this says you can use /external:I as a synonym to -isystem. You will probably need /external:templates- as well, due to the way MSVC handles warnings from templates.

Unfortunately, I cannot find any reference to any of this in the MSVC commandline documentation, nor the release notes related to the mentioned VS2017 15.6, so your mileage may vary. There is though, a CMake issue requesting support for this feature behind their SYSTEM modifier.

rubenvb
  • 74,642
  • 33
  • 187
  • 332
  • Thank you for you answer. Where do these go? Somewhere in the project properties? – IronMan Sep 10 '20 at 02:38
  • If they are not shown in the UI explicitly somewhere, you'll need to add them to either the preprocessor's or compiler's "additional arguments" field. Not sure where exactly that would be located in VS, but yes, somewhere in the project properties. – rubenvb Sep 10 '20 at 07:10