即使编译器中没有.h文件,gcc也会生成.h.gch文件

时间:2020-03-09 15:05:35

标签: c++ inheritance gcc makefile avr

我们正在为一个类项目创建一个makefile,而gcc生成.h.gch文件时遇到了问题。环顾堆栈溢出,显然这通常是由于将.h文件包含在依赖项中或具有#include *.cpp之类的东西引起的,而我们在makefile中没有这样做。

编译,更改文件并再次编译时,会出现此错误。目前,我们可以在再次编译之前使用make clean对其进行修复,但是如果可能的话,我们希望阻止生成.h.gch文件:

avr-gcc -I. -MMD  -g -mmcu=atmega324pa -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -fno-exceptions -c pwm.cpp pwm.h interruptNormal.h
cc1: warning: the "stabs" debug format cannot be used with pre-compiled headers [-Wdeprecated]
In file included from pwm.h:5:0:
interruptNormal.h:8:1: error: unknown type name 'class'
 class InterruptNormal{
 ^~~~~
interruptNormal.h:8:22: error: expected '=', ',', ';', 'asm' or '_attribute_' before '{' token
 class InterruptNormal{
                      ^
pwm.h:7:1: error: unknown type name 'class'
 class Pwm : public InterruptNormal{
 ^~~~~
pwm.h:7:11: error: expected '=', ',', ';', 'asm' or '_attribute_' before ':' token
 class Pwm : public InterruptNormal{
           ^
cc1: warning: the "stabs" debug format cannot be used with pre-compiled headers [-Wdeprecated]
interruptNormal.h:8:1: error: unknown type name 'class'
 class InterruptNormal{
 ^~~~~
interruptNormal.h:8:22: error: expected '=', ',', ';', 'asm' or '_attribute_' before '{' token
 class InterruptNormal{
                      ^
make: * [Makefile:146: pwm.o] Error 1

makefile的一部分(不确定我们可以张贴多少,因为我们想避免抄袭问题):

PRJSRC= $(wildcard *.cpp)
CPPFILES=$(filter %.cpp, $(PRJSRC))
OBJDEPS=$(CPPFILES:.cpp=.o)

%.o: %.cpp
    $(CC) $(CFLAGS) $(CXXFLAGS) -c $^

%.hex: %.out
    $(OBJCOPY) -j .text -j .data \
        -O $(HEXFORMAT) $< $@

谢谢!

1 个答案:

答案 0 :(得分:0)

avr-gcc -I. ... -c pwm.cpp pwm.h interruptNormal.h

您正在编译.h文件,这意味着GCC会为这些文件生成预编译的头文件,即.h.gch

大概这不是您想要的。从编辑中删除.h个文件,并从该文件夹中清理.gch个文件。

相关问题