Solved

Doubly Linked Node w/Maze -> Makefile

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

809 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