2011-03-02 26 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