Solved

Doubly Linked Node w/Maze -> Makefile

Posted on 2004-10-17
4
295 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 100 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 100 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 100 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 100 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

626 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