2016-03-05 133 views
0

我正在嘗試關注企鵝程序員基於文本的rpg指南(http://www.penguinprogrammer.co.uk/rpg-tutorial/introduction/)。我正在處理item類,並且我有一些未定義的JsonBox函數引用錯誤。未定義的引用與JsonBox函數

#include "Item.hpp" 
#include "Entity.hpp" 
#include "JsonBox/include/JsonBox.h" 
//#include "EntityManager.hpp" 

Item:: 
Item(std::string _id, std::string _name, std::string _description) 
    : Entity(_id) { 
    this->SetName(_name); 
    this->SetDescription(_description); 
} 

Item:: 
Item(std::string _id, JsonBox::Value& _v, EntityManager* _mgr) 
    : Entity (_id) { 
    this->Load(_v, _mgr); 
} 

void 
Item:: 
Load(JsonBox::Value& _v, EntityManager* _mgr) { 
    JsonBox::Object o = _v.getObject(); 
    this->SetName(o["name"].getString()); 
    this->SetDescription(o["description"].getString()); 

    return; 
} 

然後我正在編譯這個主文件。

//#include "EntityManager.cpp" 
#include "Item.cpp" 
#include "JsonBox/include/JsonBox.h" 

int main() { 

    return 0; 
} 

而且收到此錯誤

/tmp/cc1sZXwe.o: In function `Item::Load(JsonBox::Value&, EntityManager*)': 
main.cpp:(.text+0x286): undefined reference to `JsonBox::Value::getObject()  const' 
main.cpp:(.text+0x2d4): undefined reference to `JsonBox::Value::getString() const' 
main.cpp:(.text+0x35c): undefined reference to `JsonBox::Value::getString() const' 
/tmp/cc1sZXwe.o: In function `std::pair<std::string const,  JsonBox::Value>::~pair()': 
main.cpp:  (.text._ZNSt4pairIKSsN7JsonBox5ValueEED2Ev[_ZNSt4pairIKSsN7JsonBox5ValueEED5Ev]+ 0x18): undefined reference to `JsonBox::Value::~Value()' 
/tmp/cc1sZXwe.o: In function `std::pair<std::string const,  JsonBox::Value>::pair(std::pair<std::string const, JsonBox::Value> const&)': 
main.cpp: (.text._ZNSt4pairIKSsN7JsonBox5ValueEEC2ERKS3_[_ZNSt4pairIKSsN7JsonBox5ValueEEC5 ERKS3_]+0x3b): undefined reference to `JsonBox::Value::Value(JsonBox::Value  const&)' 
/tmp/cc1sZXwe.o: In function `std::pair<std::string const,  JsonBox::Value>::pair<std::string&&, 0ul>(std::tuple<std::string&&>&, std::tuple<>&, std::_Index_tuple<0ul>, std::_Index_tuple<>)': 
main.cpp: (.text._ZNSt4pairIKSsN7JsonBox5ValueEEC2IIOSsEILm0EEIEIEEERSt5tupleIIDpT_EERS6_I IDpT1_EESt12_Index_tupleIIXspT0_EEESF_IIXspT2_EEE[_ZNSt4pairIKSsN7JsonBox5ValueE EC5IIOSsEILm0EEIEIEEERSt5tupleIIDpT_EERS6_IIDpT1_EESt12_Index_tupleIIXspT0_EEESF _IIXspT2_EEE]+0x47): undefined reference to `JsonBox::Value::Value()' 

回答

0

裏面你main你包括Item.cpp源文件,改變你的main這可能會幫助您:

//#include "EntityManager.cpp" 
#include "Item.hpp" 
#include "JsonBox/include/JsonBox.h" 

int main() { 

    return 0; 
} 

包括源文件通常是一個不好的做法,並可能導致很多問題,你可以閱讀更多關於Including .cpp files

+0

哇,謝謝。我很擔心我沒有注意到的錯誤。 – bsmith

+0

我很高興我能幫助你。 – ppsz