Problem with multiply defined objects
I'm having trouble compiling one of my programs. Whenever I compile, the following message appears:
Code:
g++ -g uniformTest.cpp EventGen.o -I/sunshine/homes/bvz/cs302/src -I/sunshine/homes/bvz/cs302/include /sunshine/homes/bvz/cs302/objs/lib302.a -o uniform
ld: fatal: symbol `histogramEventGenerator::next(void)' is multiply-defined:
(file /var/tmp/ccqHa2jf.o type=FUNC; file EventGen.o type=FUNC);
ld: fatal: symbol `uniformEventGenerator::uniformEventGenerator(double)' is multiply-defined:
(file /var/tmp/ccqHa2jf.o type=FUNC; file EventGen.o type=FUNC);
ld: fatal: symbol `uniformEventGenerator::next(void)' is multiply-defined:
(file /var/tmp/ccqHa2jf.o type=FUNC; file EventGen.o type=FUNC);
ld: fatal: symbol `histogramEventGenerator::histogramEventGenerator(string)' is multiply-defined:
(file /var/tmp/ccqHa2jf.o type=FUNC; file EventGen.o type=FUNC);
ld: fatal: File processing errors. No output written to uniform
collect2: ld returned 1 exit status
*** Error code 1
make: Fatal error: Command failed for target `uniform'
The files that seem to be messed up are also as follows:
Code:
#include <iostream>
#include "EventGen.h"
#include "Fields.h"
uniformEventGenerator::uniformEventGenerator(double m)
{
mean = m;
}
double uniformEventGenerator::next()
{
return drand48()*mean*2;
}
histogramEventGenerator::histogramEventGenerator(string filename)
{
Fields *f;
f = new Fields(filename);
double x;
double y;
total = 0;
while( f->get_line() >= 0)
{
sscanf(f->get_field(0).c_str(), "%lf", &x);
sscanf(f->get_field(1).c_str(), "%lf", &y);
total = total + y;
tree.insert(total, new_jval_d(x));
}
}
double histogramEventGenerator::next()
{
double uniform;
double historand;
uniform = drand48()*total;
tree.find(uniform);
historand = (double)tree.getVal().d;
return historand;
}
Code:
#ifndef _EVENTGEN_H_
#define _EVENTGEN_H_
#include "rbTree.h"
#include "mystring.h"
class histogramEventGenerator {
public:
histogramEventGenerator(string filename);
double next(); // produce the next random number
protected:
rbTree<double> tree;
double total;
};
class uniformEventGenerator {
public:
uniformEventGenerator(double mean);
double next(); // produce the next random number
protected:
double mean;
};
#endif
Code:
EXE = uniform histogram bankSimulator pQueue2 pQueue3
all: $(EXE)
LIB = /sunshine/homes/bvz/cs302/include
SRC = /sunshine/homes/bvz/cs302/src
OBJS = /sunshine/homes/bvz/cs302/objs/
uniform: EventGen.o
g++ -g uniformTest.cpp EventGen.o -I$(SRC) -I$(LIB) $(OBJS)lib302.a -o uniform
histogram: EventGen.o
g++ -g histogramTest.cpp EventGen.o -I$(SRC) -I$(LIB) $(OBJS)lib302.a -o histogram
bankSimulator: EventGen.o
g++ -g bankSimulator.cpp EventGen.o pQueue2.o -I$(SRC) -I$(LIB) $(OBJS)lib302.a -o bankSimulator
pQueue2: pQueue2.o
g++ -g sortem.cpp pQueue2.o -I$(SRC) -I$(LIB) $(OBJS)lib302.a -o pQueue2
pQueue2.o: pQueue2.cpp
g++ -c -g pQueue2.cpp -I$(LIB) -I$(SRC)
pQueue3: pQueue3.o
g++ -g sortem.cpp pQueue3.o -I$(SRC) -I$(LIB) $(OBJS)lib302.a -o pQueue3
pQueue3.o: pQueue3.cpp
g++ -c -g pQueue3.cpp -I$(LIB) -I$(SRC)
EventGen.o: EventGen.cpp
g++ -c -g EventGen.cpp -I$(LIB) -I$(SRC)
clean:
rm -f core *.o $(EXE) a.out
Any help would be most welcome. If there's anything else you need to diagnose the problem, I can likely provide it. Thanks!