Consider this simple program. It gets π from a header file:
% cat main.cc #include "pi.h" #include <iostream> int main() { std::cout << pi << '\n'; return 0; } % cat pi.h constexpr auto pi = 3.14; % g++ -Wall main.cc % ./a.out 3.14 % ls a.out main.cc pi.h
Note that pi.h
is not mentioned in the compile command.
pi.h
?% g++ -Wall main.cc pi.h % ls a.out main.cc pi.h pi.h.gch % ./a.out 3.14Let’s improve the value of π:
% echo "constexpr auto pi = 3.14159;" >pi.h % g++ -Wall main.cc % ./a.out 3.14Hey, why didn’t it work?
% rm pi.h.gch % g++ -Wall main.cc % ./a.out 3.14159
#include "pi.h"
, it first looks for
pi.h.gch
, and uses that precompiled header file if it’s present.
pi.h
, it doesn’t matter,
because the compiler uses pi.h.gch
if it’s there. Ack!
foo.cc
and foo.o
.
Makefile
.