2015-12-03 37 views
0

我得到這個錯誤,我找不到解決方案任何地方..它應該是工作,但與這個錯誤我不繼續前進,我無法找到問題在哪裏。 ..C++ undefined引用類函數

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 

這是我在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 
}; 

任何人都知道可能是一個問題嗎? 謝謝

+1

問題看起來是在您的實現。 Calendar.cpp的外觀如何? –

+0

該類聲明只聲明*類變量和類函數。顯然,你的編譯器找不到那些*的定義,而你的鏈接器也不能。 – DevSolar

回答

0

變量名稱Time和類Time之間存在衝突。

static double Time; 

將時間重命名爲其他變量。

static double MyTime; 
+0

試過,仍然是相同的錯誤.. – Syntey

0

你應該編譯文件與Calendar類第一:

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

,然後嘗試將其與simims.cpp鏈接:

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

我沒有分開的文件類。只有simims.cpp和simims.h,simims.h包含多個類..我會盡量分開它..謝謝 – Syntey