0
1>game.obj : error LNK2001: unresolved external symbol "public: bool __cdecl GameStore::loadFromXml(void)" (?loadFromXml@GameStore@@QEAA_NXZ)
1>protocolgame.obj : error LNK2001: unresolved external symbol "public: struct StoreCategory * __cdecl GameStore::getStoreCategoryByName(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?getStoreCategoryByName@GameStore@@QEAAPEAUStoreCategory@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>C:\Users\Slavi Dodo\Documents\GitHub\forgottenserver\vc14\x64\Release\theforgottenserver.exe : fatal error LNK1120: 2 unresolved externals

I am so confused! I don't even understand why the error comes.

These is the declaration "gamestore.h"

#ifndef FS_GAMESTORE_H_ADCAA356C0DB44CEBA994A0D678EC92D
#define FS_GAMESTORE_H_ADCAA356C0DB44CEBA994A0D678EC92D
struct StoreOffer {
    StoreOffer(uint32_t id, uint32_t thingId, uint8_t addon, uint32_t price, uint8_t type, uint8_t state, std::string name, std::string description, std::vector<std::string> icons)
        : id(id), thingId(thingId), addon(addon), price(price), type(type), state(state), name(name), description(description), icons(icons) {}

    uint32_t id;
    uint32_t thingId;
    uint32_t price;
    uint8_t type;
    uint8_t state;
    uint8_t addon;
    std::string name;
    std::string description;
    std::vector<std::string> icons;
};

struct StoreCategory
{
    StoreCategory(std::string name, std::string description, std::vector<std::string> icons, std::vector<StoreOffer> offers)
        : name(name), description(description), icons(icons), offers(offers) {}

    std::string name;
    std::string description;
    std::string parentCategory;
    std::vector<std::string> icons;
    std::vector<StoreOffer> offers;
};

class GameStore
{
    public:
        bool reload();
        bool loadFromXml();
        StoreOffer* getStoreItemById(uint32_t id);
        StoreCategory* getStoreCategoryByName(const std::string& name);

        const std::vector<StoreCategory>& getStoreCategories() const {
            return storeCategories;
        }

        bool enabled;
        std::vector<StoreCategory> storeCategories;
};

#endif

And this is the definitions "gamestore.cpp"

#include "otpch.h"

#include "gamestore.h"

#include "pugicast.h"
#include "tools.h"

bool GameStore::reload()
{
    storeCategories.clear();
    return loadFromXml();
}

bool GameStore::loadFromXml()
{
    return true;
}

StoreOffer* GameStore::getStoreItemById(uint32_t id) {
    for (auto it : storeCategories) {
        for (auto item : it.offers) {
            if (item.id == id) {
                return &item;
            }
        }
    }
    return nullptr;
}

StoreCategory* GameStore::getStoreCategoryByName(const std::string& name) {
    auto it = std::find_if(storeCategories.begin(), storeCategories.end(), [name](StoreCategory& storeCategory) {
        return storeCategory.name == name;
    });
    return it != storeCategories.end() ? &*it : nullptr;
}

I have read more about the error, but not even found a solution to my situation. As you see the "loadFromXml" is just returning true, not accepting any arguments as well being public, the problem is very confusing!

Slavi
  • 576
  • 1
  • 3
  • 18
  • Doesn't help me at all! – Slavi May 08 '16 at 22:04
  • reopened: OP not helped by link (which is not an "exact duplicate" by any stretch of the imagination) – M.M May 08 '16 at 22:11
  • OP check that you are actually compiling `gamestore.cpp` – M.M May 08 '16 at 22:13
  • Thanks @M.M Light has just marked as duplicate however I didn't find any solution there. – Slavi May 08 '16 at 22:13
  • Yeah, I am compiling it! – Slavi May 08 '16 at 22:14
  • Rebuild all of your project. Do you see "gamestore.cpp" being compiled in the output window (since it looks like you're using Visual Studio)? Can you find "gamestore.obj" in the folder that has the obj files? – PaulMcKenzie May 08 '16 at 22:18
  • Well, @M.M I have found that it was written as "CLInclude" no t"CLCompile", thanks a lot! – Slavi May 08 '16 at 22:19
  • Cool. voting to close as "can no longer reproduce" but you could post and accept your own answer if you think it may help someone – M.M May 08 '16 at 23:29

1 Answers1

0

Check if gamestore.cpp is being compiled or not!

If not add it to projectname.vcproj in CLCompile list.

Slavi
  • 576
  • 1
  • 3
  • 18