Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Doubly Linked Node w/Maze -> Makefile

Posted on 2004-10-17
4
Medium Priority
?
300 Views
Last Modified: 2010-04-01
// 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.o:
      ${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

#
clean:
      ${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
ld:
main.o compressed: main: multiply defined
make: *** [maze] Error 1

0
Comment
Question by:edelossantos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 400 total points
ID: 12336957
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
0
 
LVL 12

Assisted Solution

by:stefan73
stefan73 earned 400 total points
ID: 12336961
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}

...so that the libraries are at the end.



Cheers!

Stefan
0
 
LVL 39

Assisted Solution

by:itsmeandnobodyelse
itsmeandnobodyelse earned 400 total points
ID: 12336964
If main() is defined only once make a 'clear' on your project and build again and/or delete all .o files manually.

Regards, Alex
0
 
LVL 9

Assisted Solution

by:jhshukla
jhshukla earned 400 total points
ID: 12344815
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.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question