Linker Errors

Hello! I am quite experienced with C, but new to C++, so this is probably something stupid. Whenever I make my code, I receive linker errors-- undefined references to all functions within class array_t.
I have my interface stored in a header file called array.h, the implementation in array.cpp, and the main function is in main.cpp. array.h is included in both .cpp files, and whenever I copy all of the functions in array.cpp and place them above the main function in main.cpp so as to skip linking, the code compiles and runs perfectly.

This leads me to believe that there might be an error with my Makefile? I'll post it here. Any suggestions would be greatly appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
CC = g++

INCLUDE = -I.

CFLAGS = -g -m32

LDFLAGS = \
	-L. \
	-L/usr/lib

LDLIBS = \
	-lc -lm

.cpp.o:
	$(CC) -c $(INCLUDE) $(CFLAGS) $<

OBJS = \
	array.o

all: main

main: main.cpp main.o $(OBJS)
	$(CC) $(CFLAGS) $(INCLUDE) -o $@ $@.o $(OBJS) $(LDFLAGS) $(LDLIBS)

clean:
	rm -f main
	rm -f *.o core
The makefile's fine.

Any chance of posting array.h/.cpp?
If class array_t is a template class, then you need to move all implementations from array.cpp to array.h and
get rid of array.cpp.

Topic archived. No new replies allowed.