2011-03-02 67 views
0

在我Method.h文件:错误: '方法' 是在此范围内声明

int method(); 

在我Method.cpp文件:

int method(){....} 

在我Main.cpp的文件:

method(); 

在我的Makefile

EXEC = main 
OBJS = Method.o 
.PHONY: all 
all: $(EXEC) 

main: Main.cpp $(OBJS) 
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $^ -o [email protected] 
Method.o : Method.h Method.cpp 

当我打电话做,它说,

Main.cpp: In function ‘int menu()’: 
Main.cpp:26: error: ‘method’ was not declared in this scope 
make: *** [main] Error 1 

可有人告诉我哪里错了? 谢谢!

+0

你在你的Main.cpp中是否#include ?更完整的代码视图将有所帮助。 – ypnos 2011-03-02 15:40:33

+0

在选择您最喜欢的答案之前,您是否需要更多信息? :-) – 2011-03-11 21:39:43

回答

0

我的第一个猜测是改变线路

OBJS = Function.o 

OBJS = Function.o Method.o 

此外, 包括Method.hMain.cpp

// In Main.cpp 
#include "Method.h" 
+0

对不起,我输入错误,我已经宣布OBJS = Method.o – Xitrum 2011-03-02 15:47:03

5

你确定你包括方法。 h文件在Main.cpp中?

+1

但我认为当声明这样的makefile时,Main.cpp不必再包括method.h? – Xitrum 2011-03-02 15:44:10

+2

@ user552279:当然是的。这是头文件存在的原因!编译器甚至不知道它是调用它的'make'。 – 2011-03-02 15:45:20

+0

谢谢,现在我明白了这个问题 – Xitrum 2011-03-02 15:54:08