I am writing a C++ program that uses Boost, using XCode 4.1 as IDE and compiler front-end. I get quite a lot of warnings in various Boost headers, and I would like to disable all warnings for those headers (but still enable them for my own project). Is there an easy way to do so?
Asked
Active
Viewed 2,040 times
3
-
Not in general for a specific header set and instantiations from them. But for the parts in your translation unite see [here](http://stackoverflow.com/questions/965093/selectively-disable-gcc-warnings-for-only-part-of-a-translation-unit). – Georg Fritzsche Sep 04 '11 at 21:59
-
@Georg: I had read that question, but 1. I'm not using GCC; 2. I don't wanna have to write multiple `#pragma` in each .cpp file, whenever I'm including a Boost header. I'd like a more general solution, if possible. – Andrea Bergia Sep 04 '11 at 22:11
-
What compiler are you using then? – Mark B Sep 04 '11 at 22:37
-
@Andrea: See [here](http://clang.llvm.org/docs/UsersManual.html#diagnostics_pragmas) for Clang. I'm afraid a general solution isn't really possible if you think of boost template instantiations in your code. – Georg Fritzsche Sep 04 '11 at 22:59
2 Answers
3
Another solution, that I found to work in Xcode 5.x (yet it is expected to work with Xcode 4).
In the Build Settings of the Boost depending target, instead of setting the headers' path under Header Search Paths
, I write it under Other C++ Flags
, prefixed by -isystem

Ad N
- 7,930
- 6
- 36
- 80
3
I have found a decent workaround, based on what @Georg Fritzsche suggested:
I have added the various incriminated boost headers to the .pch file (the pre-compiled header), and wrapped them around a #pragma push
- #pragma pop
block, like this:
// We do not want to have warnings about Boost headers!
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#pragma GCC diagnostic ignored "-Wshadow"
#include <boost/date_time/posix_time/posix_time_types.hpp>
...
#pragma GCC diagnostic pop
This works perfectly, and it's not as annoying as having to surround the boost headers with #pragma
in each .cpp file, as I feared.

Andrea Bergia
- 5,502
- 1
- 23
- 38
-
1I have added a .pch file to my project and also enabled precompiled headers but my warnings are not gone. I have the same issue you had. Do I need to do something else ? I have included the headers file which gives warnings in the .pch file with no luck. – Adrian Aug 24 '13 at 18:05