std :: unordered_map和链接器错误

Kac*_*per 1 c++ dll linker

我在编译新项目时遇到了一些问题.

编译器输出:

1>------ Build started: Project: IRPCore, Configuration: Debug Win32 ------
1>  core.cpp
1>     Creating library D:\Repo\Inter Role Play Gamemode\sa-mp-0.2-plugin-sdk\IRP\Debug\IRPCore.lib and object D:\Repo\Inter Role Play Gamemode\sa-mp-0.2-plugin-sdk\IRP\Debug\IRPCore.exp
1>core.obj : error LNK2001: unresolved external symbol "public: static class std::tr1::unordered_map<int,struct item,class std::hash<int>,struct std::equal_to<int>,class std::allocator<struct std::pair<int const ,struct item> > > core::itemCache" (?itemCache@core@@2V?$unordered_map@HUitem@@V?$hash@H@std@@U?$equal_to@H@3@V?$allocator@U?$pair@$$CBHUitem@@@std@@@3@@tr1@std@@A)
1>main.obj : error LNK2001: unresolved external symbol "public: static class std::tr1::unordered_map<int,struct item,class std::hash<int>,struct std::equal_to<int>,class std::allocator<struct std::pair<int const ,struct item> > > core::itemCache" (?itemCache@core@@2V?$unordered_map@HUitem@@V?$hash@H@std@@U?$equal_to@H@3@V?$allocator@U?$pair@$$CBHUitem@@@std@@@3@@tr1@std@@A)
1>D:\Repo\Inter Role Play Gamemode\sa-mp-0.2-plugin-sdk\IRP\Debug\IRPCore.dll : fatal error LNK1120: 1 unresolved externals
Run Code Online (Sandbox Code Playgroud)

core.cpp来了

#include <iostream>
#include <unordered_map>
#include "core.h"

core::core(void)
{

}

core::~core(void)
{

}

void core::Item_Insert(int uid, item Item)
{
    core::itemCache.insert(std::make_pair<int,item>(uid, Item));

    return;
}

std::string core::convertNativeStringToString(AMX *amx, cell input)
{
    char *string = NULL;
    amx_StrParam(amx, input, string);
    return string ? string : "";
} 
Run Code Online (Sandbox Code Playgroud)

我应该链接更多的libs吗?

提前致谢.

编辑:核心定义来自core.h

class core
{
    public:
        static std::unordered_map<int, item> itemCache;
        core(void);
        ~core(void);
        static void Item_Insert(int uid, item Item);
        static std::string convertNativeStringToString(AMX *amx, cell input);
    private:
};
Run Code Online (Sandbox Code Playgroud)

Pet*_*ker 5

添加core::itemCachecore.cpp 的定义.通常,类的静态数据成员在类定义中声明并在源文件中定义.


clo*_*fin 5

正如@Pete Becker 所说,把它放在 cpp 的顶部:

std::unordered_map<int, item> core::itemCache;
Run Code Online (Sandbox Code Playgroud)

除了

static std::unordered_map<int, item> itemCache;
Run Code Online (Sandbox Code Playgroud)

已经在.h。