使用 JsonBox 函数的未定义引用

Undefined reference with JsonBox functions

本文关键字:未定义 引用 函数 JsonBox 使用      更新时间:2023-10-16

我正在尝试遵循企鹅程序员基于文本的RPG指南(http://www.penguinprogrammer.co.uk/rpg-tutorial/introduction/)。 我正在处理项目类,并且 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()'

在包含 Item.cpp 源文件的main中,将main更改为此文件可能会帮助您:

//#include "EntityManager.cpp"
#include "Item.hpp"
#include "JsonBox/include/JsonBox.h"
int main() {
    return 0;
}
包含

源文件通常是一种不好的做法,可能会导致许多问题,您可以阅读有关包含.cpp文件的更多信息