Cannot deploy the precompiled header (.gch)

1.4k Views Asked by At

Could you, please, help me with warning: pch.hpp.gch: not used because '__STDC_IEC_559__' not defined emerging when I am trying to deploy a gcc-generated precompiled header with boost headers?

Here is my toy model. File pch.hpp:

#include <vector>
#include <string>
#include <iostream>

#include <boost/bind.hpp>

and its complementary pch.cpp

#include "pch.hpp"

To produce the precompiled header, I invoke the following command: g++ -std=c++11 -c -x c++-header pch.cpp -o pch.hpp.gch, where gcc is of version 4.8.2.

Now, there is the bla.cpp file, where I want eventually the precompiled header to be utilized:

#include "pch.hpp"

int main() {
   #ifdef __STDC_IEC_559__
   std::cout << "__STDC_IEC_559__ is defined by the compiler as " << __STDC_IEC_559__ << std::endl;
   #else
   std::cout << "__STDC_IEC_559__ is NOT defined by the compiler as " << __STDC_IEC_559__ << std::endl;
   #endif

   std::vector<std::string> vs {"One", "Two", "Three"};
   for (auto&& v : vs) std::cout << v << ", ";
   std::vector<int> vi {1,2,3};
   for (auto&& v : vi) std::cout << v << ", ";
   std::cout << '\n';
   return 0;
}

I compile it with this command: g++ -std=c++11 -Winvalid-pch -H bla.cpp.

The output is:

bla.cpp:1:19: warning: pch.hpp.gch: not used because `__STDC_IEC_559__' not defined [-Winvalid-pch]
 #include "pch.hpp"
                   ^
x pch.hpp.gch
. pch.hpp
...

So, the code compiles, but the precompiled header is not deployed. If I run the compiled code, I see the following output:

__STDC_IEC_559__ is defined by the compiler as 1
One, Two, Three, 1, 2, 3, 

Is there a way to make use of my precompiled header? Must I generate it differently?..

Observe that if there is no boost header in my pch.hpp, i.e. only the ones from std lib, the precompiled header is deployed.

Thank you in advance! Oleksii

0

There are 0 best solutions below