0

Suppose I have A.h, A.cpp, B.h and B.h.gch (I have downloaded B from Internet)

How can I compile my code (and create an executable) ?

I have an error when I do

g++ -c B.h.gch
Mourad Qqch
  • 373
  • 1
  • 5
  • 16

1 Answers1

2

You can practically have only one single precompiled header myheader.h and quite often that single header is including other ones. See this answer for more.

You compile that C++ header with g++ -c myheader.h (and other relevant options, notably -O , -g, -Wall , -Idirname ...; they should be the same as for your object files). In practice you should have a Makefile and use make (run once make -p to understand the builtin rules). The CXXFLAGS there should be used both for object files and for the precompiled header.

You don't change any #include directive (but in practice all your *.cc or *.cpp files should have only one).

Read also the Precompiled headers section.

Community
  • 1
  • 1
Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547