Solved

Doubly Linked Node w/Maze -> Makefile

Posted on 2004-10-17
4
273 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

861 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now