TLD
TLD

Reputation: 8135

Error: ‘method’ was not declared in this scope

In my Method.h file:

int method();

In my Method.cpp file:

int method(){....}

In my Main.cpp file:

method();

In my 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

When i call make, it says that

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

Can anybody tell me where I was wrong? Thank you!

Upvotes: 0

Views: 2183

Answers (2)

Arun
Arun

Reputation: 20383

My first guess is to change the line

OBJS = Function.o

to

OBJS = Function.o Method.o

Also, Include Method.h in Main.cpp

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

Upvotes: 0

Bo Persson
Bo Persson

Reputation: 92211

Are you sure you include the method.h file in Main.cpp?

Upvotes: 5

Related Questions