错误:未在此范围内声明'method'

时间:2011-03-02 15:36:48

标签: c++

在我的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 $@
Method.o : Method.h Method.cpp

当我打电话给make时,它说

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

谁能告诉我哪里错了? 谢谢!

2 个答案:

答案 0 :(得分:5)

您确定在Main.cpp中包含method.h文件吗?

答案 1 :(得分:0)

我的第一个猜测是改变线

OBJS = Function.o

OBJS = Function.o Method.o

此外,Method.h

中加入Main.cpp
// In Main.cpp
#include "Method.h"