Getting an error when compiling a project

Write your question here.
As soon as my project has two header files I always get an error in file Makefile.win
on line 25. The error is:
C:\Martin\MalikChapter1\TestBook.o TestBook.cpp:(.text+0x0): multiple definition of `main'
C:\Martin\MalikChapter1\main.o main.cpp:(.text+0x0): first defined here
C:\Martin\MalikChapter1\collect2.exe [Error] ld returned 1 exit status
25 C:\Martin\MalikChapter1\Makefile.win recipe for target 'myAuthor.exe' failed
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
28
29
30
31
32
33
34
35
36
  Put the code you need help with here.

CPP      = g++.exe
CC       = gcc.exe
WINDRES  = windres.exe
OBJ      = main.o Author.o Book.o TestBook.o
LINKOBJ  = main.o Author.o Book.o TestBook.o
LIBS     = -L"C:/Program Files/Dev-Cpp/MinGW64/lib32" -L"C:/Program Files/Dev-Cpp/MinGW64/x86_64-w64-mingw32/lib32" -static-libgcc -m32
INCS     = -I"C:/Program Files/Dev-Cpp/MinGW64/include" -I"C:/Program Files/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.8.1/include"
CXXINCS  = -I"C:/Program Files/Dev-Cpp/MinGW64/include" -I"C:/Program Files/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.8.1/include" -I"C:/Program Files/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.8.1/include/c++"
BIN      = myAuthor.exe
CXXFLAGS = $(CXXINCS) -m32
CFLAGS   = $(INCS) -m32
RM       = rm.exe -f

.PHONY: all all-before all-after clean clean-custom

all: all-before $(BIN) all-after

clean: clean-custom
	${RM} $(OBJ) $(BIN)

$(BIN): $(OBJ)
	$(CPP) $(LINKOBJ) -o $(BIN) $(LIBS)

main.o: main.cpp
	$(CPP) -c main.cpp -o main.o $(CXXFLAGS)

Author.o: Author.cpp
	$(CPP) -c Author.cpp -o Author.o $(CXXFLAGS)

Book.o: Book.cpp
	$(CPP) -c Book.cpp -o Book.o $(CXXFLAGS)

TestBook.o: TestBook.cpp
	$(CPP) -c TestBook.cpp -o TestBook.o $(CXXFLAGS)
It looks like you have defined a main function in both main.cpp and TestBook.cpp. A program can only have one main function.
Okay Peter87, I went to my original project called Author and I deleted the three files that belong to the book program that inherits from author. I then created a new project and I put in the three files, book.h, book.cpp and the main program there called TestBook and I still got the same error. Now what should I do if I have two classes , i.e the main class and a second class that inherits from the main one because both of them have their main programs?

Thanks.
If I run the first class called Author on its own with its three files , Author.h , Author.cpp and its main it runs 100% okay.
Also when I run the second class Book which also have its three files , Book.h , Book.cpp and its main called TestBook inherits from Author and I put all the the six files in one big file, the Book class also run 100% okay.
But that is not a professional was of working with projects and classes that inherit from other classes.

Please help.

Thanks
A program can only contain one global function named main.
Your terminology is all messed up and makes me wonder if you know what you're doing or if you're cargo-cult programming. Files don't inherit from each other. Classes don't run. There is no such thing as "the main class".
When I removed one of the main driver testing programs from the project each one ran 100% okay. So you are 100% correct Peter87, and thanks for that. I learned that the hard way. I really never new what was the problem.

Regards.
Topic archived. No new replies allowed.