makefile issue undefined reference to main

I'm getting an undefined reference to 'main' error. I tried a few things and can't seem to quite get it. I'm trying to make the name of my executable hw1.exe
any suggestions? Thanks.


CC = g++
CFLAGS = -g -Wall

hw1.exe : BaseballPlayer.o Pitcher.o Hitter.o PlayerDatabase.o
$(CC) $(CFLAGS) -o hw1.exe BaseballPlayer.o Pitcher.o Hitter.o PlayerDatabase.o

BaseballPlayer.o : BaseballPlayer.h BaseballPlayer.cpp
$(CC) $(CFLAGS) -c BaseballPlayer.cpp

Pitcher.o : Pitcher.h Pitcher.cpp
$(CC) $(CFLAGS) -c Pitcher.cpp

Hitter.o : Hitter.h Hitter.cpp
$(CC) $(CFLAGS) -c Hitter.cpp

PlayerDatabase.o : PlayerDatabase.h PlayerDatabase.cpp
$(CC) $(CFLAGS) -c PlayerDatabase.cpp


clean :
-rm *.o hw1.exe
I think you misinterpreted code tags. http://www.cplusplus.com/articles/firedraco1/
sorry about that. I've been running on fumes the last few days

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
CC = g++
CFLAGS = -g -Wall

hw1.exe : BaseballPlayer.o Pitcher.o Hitter.o PlayerDatabase.o
$(CC) $(CFLAGS) -o hw1.exe BaseballPlayer.o Pitcher.o Hitter.o PlayerDatabase.o

BaseballPlayer.o : BaseballPlayer.h BaseballPlayer.cpp
$(CC) $(CFLAGS) -c BaseballPlayer.cpp

Pitcher.o : Pitcher.h Pitcher.cpp
$(CC) $(CFLAGS) -c Pitcher.cpp

Hitter.o : Hitter.h Hitter.cpp
$(CC) $(CFLAGS) -c Hitter.cpp

PlayerDatabase.o : PlayerDatabase.h PlayerDatabase.cpp
$(CC) $(CFLAGS) -c PlayerDatabase.cpp


clean :
-rm *.o hw1.exe
I don't see anything terribly wrong with your makefile. If anything, lines 5, 8, 11, 14, 17, and 21 should begin with a tab; I doubt that would break it, though. Also, I don't think CFLAGS are necessary on line 5--LDFLAGS are typically passed for that; again, this wouldn't break it.

So, what we need is a little more information:

1. Where is the main function? Please post its signature.
2. What is the output of 'make clean; make'

Undefined reference errors come from the linker (ld). It often means that either a function was not defined or that an object file was left out. For example, if there's a hw1.cpp, main.cpp or something similar that contains main, it would need to be added in the makefile.
Last edited on
Topic archived. No new replies allowed.