0

I am trying to follow the penguin programmer text-based rpg guide (http://www.penguinprogrammer.co.uk/rpg-tutorial/introduction/). I am working on the item class and I am having some undefined reference errors with JsonBox functions.

#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;
}

Then I am compiling this main.

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

int main() {

  return 0;
}

And getting this error

/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()'
bsmith
  • 31
  • 3

1 Answers1

0

Inside your main you include Item.cpp source file, changing your main to this might help you:

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

int main() {

    return 0;
}

Including source files is usually a bad practice, and can cause many problems, you can read more about Including .cpp files

Community
  • 1
  • 1
ppsz
  • 342
  • 1
  • 10