【发布时间】:2016-07-03 06:40:43
【问题描述】:
我在编译我的项目时遇到了下一个错误。
./PC.h:15:12: error: unknown type name 'InstructionMemory'
PC *new_pc(InstructionMemory *memoria);
^
./PC.h:17:1: error: unknown type name 'InstructionMemory'
InstructionMemory *get_memory(PC *programCounter);
^
2 errors generated.
In file included from main.c:5:
./InstructionRegister.h:7:36: error: unknown type name 'BankRegister'
int opera(InstructionRegister *IR, BankRegister *bank);
但这对我没有意义,我查看文件并且它们是头文件,所以我知道您不能在头文件中使用#include。所以我不知道我做错了什么。
有我的PC.h文件的内容:
typedef struct PC PC;
PC *new_pc(InstructionMemory *memoria);
int getpc(PC *programCounter);
InstructionMemory *get_memory(PC *programCounter);
char *fecth(PC *programCounter);
char *linea_actual(PC *programCounter);
我使用下一个makefile来编译:
CC = gcc
CFLAGS=-I
DEPS = ALU.h InstructionRegister.h Rebasing.h BankRegister.h MemoryInstruction.h ControlUnit.h PC.h
run: exect
./exect $(EX)
%.o: %.c $(DEPS)
$(CC) -c $< $(CFLAGS)
exect: ALU.c InstructionRegister.c Rebasing.c BankRegister.c MemoryInstruction.c main.c ControlUnit.c PC.c
gcc -o exect InstructionRegister.c Rebasing.c BankRegister.c MemoryInstruction.c main.c ControlUnit.c PC.c -I.
clean:
rm -f *.o
【问题讨论】:
-
PC.h需要包含定义InstructionMemory的任何内容。或者使用前向声明 -
你不需要编译头文件。
-
"我知道你不能在头文件中使用#include" - 是的,你可以。
-
“我知道你不能在头文件中使用#include”。谁说的?
-
感谢大家的回复。
标签: c makefile compilation compiler-errors