Compiling the following:
// file main.cpp
#include <string>
#include <boost/lexical_cast.hpp>
int main()
{
boost::lexical_cast<std::string>( 656.16 );
return 0;
}
yields to this:
/usr/local/include/boost/lexical_cast.hpp:1184: warning: ISO C++ does not support the ‘%lg’ printf format
Why? How to avoid this warning?
I GCC, there’s a simple trick to silence all warnings from a specific library’s headers. Simply treat them as system headers. This is safe, as far as I know, and I use it as a course of standard practice.
That is, tweak your command line to use
-isysteminstead of-Ito specify the Boost header location. Everything else stays the same.For instance, this is taken from a
Makefileof one of my projects:Note: it is important that you don’t silence warnings in general in your projects. On the contrary, you should treat all warnings as errors (
-Werror) and warn as much as possible (.e.g.-Wall -Wextra). The above disables only those warnings caused by Boost, not from your own code. This is as it should be.