Skip to content

Instantly share code, notes, and snippets.

@sparkprime
Created May 5, 2016 23:48
Show Gist options
  • Save sparkprime/4cd03cd015d7ba78b82d0f6347177244 to your computer and use it in GitHub Desktop.
Save sparkprime/4cd03cd015d7ba78b82d0f6347177244 to your computer and use it in GitHub Desktop.
g++ pch problem
#ifndef HEADER_h
#define HEADER_h
#include <subheader.h>
int global_var;
static inline int f(int p)
{
return p * p;
}
#endif
#include <cstdlib>
#include <iostream>
#include <header.h>
int main(void)
{
std::cout << "global_var = " << global_var << std::endl;
std::cout << "f(10) = " << f(10) << std::endl;
std::cout << "global_var2 = " << global_var2 << std::endl;
std::cout << "g(10) = " << g(10) << std::endl;
return EXIT_SUCCESS;
}
%.h.gch: %.h
@mkdir -p out
g++ -Wall -Wextra -pedantic -x c++-header -I. $< -o out/$@
main: main.cpp header.h.gch
@mkdir -p out
g++ -Wall -Wextra -pedantic -Winvalid-pch -I out $< -o out/$@
clean:
rm -rfv out *~
#ifndef SUBHEADER_h
#define SUBHEADER_h
int global_var2;
static inline int g(int p)
{
return 42 * p;
}
#endif
@sparkprime
Copy link
Author

g++ -Wall -Wextra -pedantic -x c++-header -I. header.h -o out/header.h.gch
g++ -Wall -Wextra -pedantic -Winvalid-pch -I out main.cpp -o out/main
main.cpp:4:20: fatal error: header.h: No such file or directory
 #include <header.h>
                    ^
compilation terminated.
make: *** [main] Error 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment