0

I'm getting this errors and I can't find solution anywhere.. It's supposed to be working but with this errors I'm not moving on and I can't find where is problem...

g++ -std=c++0x -pedantic -Wall -Wextra simims.cpp -o simims
/tmp/ccZa3W7s.o: In function `Calendar::Init(double, double)':
simims.cpp:(.text+0x5d): undefined reference to `Calendar::start_time'
simims.cpp:(.text+0x6a): undefined reference to `Calendar::Time'
simims.cpp:(.text+0x77): undefined reference to `Calendar::end_time'
/tmp/ccZa3W7s.o: In function `Calendar::Push(Process*, double)':
simims.cpp:(.text+0x9f): undefined reference to 
`Calendar::listOfEvents[abi:cxx11]'
/tmp/ccZa3W7s.o: In function `Calendar::Pop(std::__cxx11::list<Process, 
std::allocator<Process> >)':
simims.cpp:(.text+0x1b9): undefined reference to 
`Calendar::listOfEvents[abi:cxx11]'
/tmp/ccZa3W7s.o: In function `Calendar::PopLists[abi:cxx11](double)':
simims.cpp:(.text+0x1da): undefined reference to 
`Calendar::listOfEvents[abi:cxx11]'
/tmp/ccZa3W7s.o: In function `Calendar::Run()':
simims.cpp:(.text+0x230): undefined reference to `Calendar::Time'
simims.cpp:(.text+0x24a): undefined reference to 
`Calendar::listOfEvents[abi:cxx11]'
simims.cpp:(.text+0x29a): undefined reference to `Calendar::end_time'
simims.cpp:(.text+0x2b1): undefined reference to `Calendar::Time'
simims.cpp:(.text+0x2b9): undefined reference to `Calendar::Time'
simims.cpp:(.text+0x2c1): undefined reference to `Calendar::start_time'
simims.cpp:(.text+0x2d9): undefined reference to `Process::Behavior()'
simims.cpp:(.text+0x2f8): undefined reference to `Calendar::Time'
simims.cpp:(.text+0x30c): undefined reference to `Calendar::Time'
/tmp/ccZa3W7s.o: In function `Process::Wait(double)':
simims.cpp:(.text+0x3ef): undefined reference to `Calendar::Time'
collect2: error: ld returned 1 exit status

Here is my class in C++:

class Calendar
{
public:
    static double start_time;
    static double Time;
    static double end_time; 
    static list<list<Process>> listOfEvents;
    Calendar();
    ~Calendar();
    static void Run();
    static void Push(Process*, double t);
    static Process * Pop(list<Process> listOfLists);
    static list<Process> PopLists(double t);
    static void Init(double, double);
    static Calendar * GetInstance()     // Singleton
    {
        if(instance == NULL)
            instance = new Calendar();
        return instance;
    }
private:
    static Calendar * instance;     // Singleton variable
};

Anyone know where could be a problem? Thank you

Syntey
  • 147
  • 1
  • 15
  • 1
    Problems look to be in your implementation. What does Calendar.cpp look like? – Mohamad Elghawi Dec 03 '15 at 16:21
  • That class declaration only *declares* the class variables and class functions. Apparently, your compiler cannot find the *definition* of those, and your linker can't either. – DevSolar Dec 03 '15 at 16:25

2 Answers2

0

There is a collision between variable name Time and the class Time.

static double Time;

Rename the Time to some other variable.

static double MyTime;
EylM
  • 5,967
  • 2
  • 16
  • 28
0

You should compile the file with the Calendar class first:

g++ -std=c++0x -pedantic -Wall -Wextra Calendar.cpp -o calendar.o

and then try to link it with simims.cpp:

g++ -std=c++0x -pedantic -Wall -Wextra calendar.o simims.cpp -o simims
syntagma
  • 23,346
  • 16
  • 78
  • 134
  • I don't have divided files to classes.. Only simims.cpp and simims.h, simims.h contains multiple classes.. I will try to divide it.. Thanks – Syntey Dec 03 '15 at 17:24