Problem with multiply defined objects

This is a discussion on Problem with multiply defined objects within the C++ Programming forums, part of the General Programming Boards category; I'm having trouble compiling one of my programs. Whenever I compile, the following message appears: Code: g++ -g uniformTest.cpp EventGen.o ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    5

    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!

  2. #2
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    You're not trying to include cpp files by any chance are you?

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    5

    Doh!

    Ah, yes, that's likely the problem. I'd not considered that.

    Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with pointer to vector objects
    By ryeguy in forum C++ Programming
    Replies: 5
    Last Post: 02-11-2008, 07:42 AM
  2. defined function return type problem
    By mikahell in forum C++ Programming
    Replies: 5
    Last Post: 01-12-2008, 09:04 PM
  3. User defined 2-D array problem
    By Turtal in forum C Programming
    Replies: 5
    Last Post: 12-15-2007, 01:23 AM
  4. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  5. Problem with destructors.
    By Hulag in forum C++ Programming
    Replies: 7
    Last Post: 06-11-2004, 01:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21