我正在尝试按照企鹅程序员基于文本的RPG指南(http://www.penguinprogrammer.co.uk/rpg-tutorial/introduction/)。我正在处理item类,我对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 :(得分:0)
在您的main
内包含Item.cpp源文件,将main
更改为此可能会对您有所帮助:
//#include "EntityManager.cpp"
#include "Item.hpp"
#include "JsonBox/include/JsonBox.h"
int main() {
return 0;
}
包含源文件通常是一种不好的做法,并且可能会导致许多问题,您可以阅读有关Including .cpp files的更多信息