multiple definitions error.

I'm trying to compile a project in Unix but keep getting the following errors. I have tried compiling in visual studio but am not seeing the same thing.. any advice?



main.o: In function `Median(int*, unsigned long)':
main.cpp:(.text+0xa0): multiple definition of `Median(int*, unsigned long)'
make
g++47 -std=c++11 -Wall -Wextra -I. -I/home/courses/cop3330p/LIB/cpp -ostats.x st ats.o main.o
main.o: In function `Mean(int const*, unsigned long)':
main.cpp:(.text+0x0): multiple definition of `Mean(int const*, unsigned long)'
stats.o:stats.cpp:(.text+0x0): first defined here
main.o: In function `Median(int*, unsigned long)':
main.cpp:(.text+0xa0): multiple definition of `Median(int*, unsigned long)'
stats.o:stats.cpp:(.text+0xa0): first defined here
stats.o: In function `Median(int*, unsigned long)':
stats.cpp:(.text+0xde): undefined reference to `Sort(int*, unsigned long)'
main.o: In function `Median(int*, unsigned long)':
main.cpp:(.text+0xde): undefined reference to `Sort(int*, unsigned long)'
collect2: error: ld returned 1 exit status
make: *** [stats.x] Error 1
the makefile was provided for us.. here it is


ranint.x: ranint.o xran.o
$(CC) -oranint.x ranint.o xran.o

ranint.o: $(CPP)/xran.h ranint.cpp
$(CC) -c ranint.cpp

ranuint.x: ranuint.o xran.o
$(CC) -oranuint.x ranuint.o xran.o

ranuint.o: $(CPP)/xran.h ranuint.cpp
$(CC) -c ranuint.cpp

xran.o: $(CPP)/xran.h $(CPP)/xran.cpp
$(CC) -c $(CPP)/xran.cpp






Make sure any functions in xran.h have the whole function.

Options if that didn't work:
-Try to slap everything into one file.
-Try a different compiler.

*and then if that doesn't work, show code
Last edited on
> Make sure any functions in xran.h have the whole function.
¿ah? ¿what does that mean?

http://www.cplusplus.com/forum/general/140198/
The error message is telling you that both `main.cpp' and `stats.cpp' define the `Median()' function

http://www.cplusplus.com/forum/general/113904/
and that none have the definition of `Sort()'


> and then if that doesn't work, show code
that should be the first thing to do, ¿why are we working blind?
Last edited on
Topic archived. No new replies allowed.