Doubly Linked Node w/Maze -> Makefile

// Do not understand compilation errors.

# Makefile:
#        It uses the C++ Compiler with all warnings and
#        full debugging; will create a single executable called 'maze'
# ---------------------------------------------------------------
# the compiler
CPP = cxx
# compiler flags
CFLAGS = -L/usr/lib/cmplrs/cxx -DPOSIX_4D9 -w0 -gall
# linker flags to link in the libraries libm.a and libtask.a
LFLAGS = -lm -ltask
RM = rm -f
# ----------------------------------------------------------------
# Explanation of macros:
#     $< is any dependent file which is out of file1
#     $* is the target's basename (without extension)
#     $@ is the target's fullname
# add suffix .cpp since it is not a default with make util
.SUFFIXES:      .cpp .o
# implicit rule for compilation only:
      ${CPP} -c ${CFLAGS} $<

OFILES=            maze.o util.o main.o

HFILES=            util.h

# dependencies
default:      maze      
maze:           $(OFILES)
            ${CPP} ${CFLAGS} ${LFLAGS} $(OFILES) -o $@

maze.o:            maze.cpp util.h

util.o:      util.cpp util.h main.cpp

      ${RM} *.o
      ${RM} core
veryclean:      clean
      ${RM}  maze  

make =

[edeloss2@pegasus hw5]$ make
cxx -L/usr/lib/cmplrs/cxx -DPOSIX_4D9 -w0 -gall -lm -ltask maze.o util.o main.o
-o maze
ld (prelink):
main.o compressed: main: multiply defined
ld (prelink):
main.o compressed: main: multiply defined
ld (prelink):
main.o compressed: main: multiply defined
main.o compressed: main: multiply defined
make: *** [maze] Error 1

Who is Participating?
itsmeandnobodyelseConnect With a Mentor Commented:
Del, check maze.cpp and main.cpp if the function main() is defined more than once. Any global function name may occur only once in the whole project.

Regards, Alex
stefan73Connect With a Mentor Commented:
Hi edelossantos,
Are you sure you have only one function "main" in all your .c files?

You should also re-order you linking command:
maze:           $(OFILES)
          ${CPP} ${CFLAGS} -o $@ $(OFILES) ${LFLAGS} that the libraries are at the end.


itsmeandnobodyelseConnect With a Mentor Commented:
If main() is defined only once make a 'clear' on your project and build again and/or delete all .o files manually.

Regards, Alex
jhshuklaConnect With a Mentor Commented:
grep -n "main(" your_code_directory/*
to locate all instances of (and calls to) main function. although calls to main will cause compile errors it is perfectly valid text.
I intentionally used only opening paren 'coz main may have some arguments.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.