我们正在为一个类项目创建一个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) $< $@
谢谢!
答案 0 :(得分:0)
avr-gcc -I. ... -c pwm.cpp pwm.h interruptNormal.h
您正在编译.h
文件,这意味着GCC会为这些文件生成预编译的头文件,即.h.gch
。
大概这不是您想要的。从编辑中删除.h
个文件,并从该文件夹中清理.gch
个文件。