guest7 0 Junior Poster

Hi,

I have two directories and each directory has a *.cpp and *.h and a Makefile. I am also creating an instance of the class of program1(in one directory) in program2(in other directory). I have a main Makefile that makes the two makefiles in each directory. i am getting the following error:

ld: duplicate symbol _main in ../hello2_prog_dir/hello2.o and hello1.o

I am attaching the directory structure and main makefile for reference.

Directory structure
-----------------------------------------------------------------------------------
./hello1_prog_dir/hello1.cpp
./hello1_prog_dir/hello1.h
./hello1_prog_dir/Makefile
./hello2_prog_dir/hello2.cpp
./hello2_prog_dir/hello2.h
./hello_2_prog_dir/Makefile
Makefile
-----------------------------------------------------------------------------------

###Main makefile:

CC = g++ -DDEBUG -Wall
CFLAGS =

ifeq (solaris, $(OSTYPE))
MFLAGS = -D_NEED_REDEFINE_RAND_MAX_
endif

RANLIB = ranlib
AR = ar

.SUFFIXES: .o .cpp

TRGTS = bmc bmcp

math: $(TRGTS)
$(CC) $(CFLAGS) $(MFLAGS) -o $(PROG) $(TRGTS)

all: math

bmc:
cd ./hello1_prog_dir; make bmc

bmcp:
cd ./hello2_prog_dir; make bmcp

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

clean:
rm -f *.o *~
cd ./hello1_prog_dir; make clean
cd ./hello2_prog_dir; make clean

---------------------------------------------------------------------------------

Output :


cd ./hello1_prog_dir; make bmc
g++ -DDEBUG -Wall -c hello1.cpp -ggdb -o hello1.o
g++ -DDEBUG -Wall -c ../hello2_prog_dir/hello2.cpp -ggdb -o ../hello2_prog_dir/hello2.o
g++ -DDEBUG -Wall hello1.o hello1.h ../hello2_prog_dir/hello2.o ../hello2_prog_dir/hello2.h -o bmc
ld: duplicate symbol _main in ../hello2_prog_dir/hello2.o and hello1.o

collect2: ld returned 1 exit status
make[1]: *** [bmc] Error 1
make: *** [bmc] Error 2

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.