I'm trying to force GCC to use the precompiled header (pch.h
). But I am getting an error:
.
.
.
g++ -c -std=c++20 -Wall -Wextra -Wpedantic -Wshadow -H -O3 -flto -include pch.h PeykNowruzi.cpp
! ./pch.h.gch
mingw32-make: *** [makefile:10: PeykNowruzi.o] Error 1
This is my makefile:
CXX = g++
CXXFLAGS = -std=c++20 -Wall -Wextra -Wpedantic -Wshadow -H -O3 -flto
all: PeykNowruzi
PeykNowruzi: PeykNowruzi.o Util.o CharMatrix.o
$(CXX) PeykNowruzi.o Util.o CharMatrix.o -o runPeykNowruzi
PeykNowruzi.o: PeykNowruzi.cpp CharMatrix.h pch.h.gch
$(CXX) -c $(CXXFLAGS) -include pch.h PeykNowruzi.cpp
Util.o: Util.cpp Util.h pch.h.gch
$(CXX) -c $(CXXFLAGS) -include pch.h Util.cpp
CharMatrix.o: CharMatrix.cpp CharMatrix.h Util.h pch.h.gch
$(CXX) -c $(CXXFLAGS) -include pch.h CharMatrix.cpp
pch.h.gch: pch.h
$(CXX) -c $(CXXFLAGS) pch.h -o pch.h.gch
clean:
rm *.o runPeykNowruzi
First of all, GCC does not name the header as pch.h.gch
and instead it names it as pch.h
. When I manually delete all the .o files and the .exe and the pch.h(the .gch one, not the .h one), then run make, it builds succesfully. But when I rename the precompiled header to pch.h.gch
, it fails as I showed above. Also when I remove the pch.h
, then I expect it to compile it again before compiling other source files (which depend on pch.h). I run make, it compiles pch.h
, then starts to compile PeykNowruzi.cpp
and fails.
I fix this problem by deleting .o
and .exe
and pch.h
files altogether and then running make again.
Am I doing something wrong that I should not do? And why GCC on my Windows machine does not name the precompiled header as pch.h.gch
?
EDIT: Regarding my 1st question, I just found out that Windows 10 File Explorer was hiding the extension of all files. I checked a box and now it shows the precompiled header as pch.h.gch
.