C++ std::无序的_映射和链接器错误

C++ std::无序的_映射和链接器错误,c++,dll,linker,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 Ro

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

编译器输出:

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
1>----构建已启动:项目:IRPCore,配置:调试Win32------
1> core.cpp
1> 创建库D:\Repo\Inter-Role-Play Gamemode\sa-mp-0.2-plugin-sdk\IRP\Debug\IRPCore.lib和对象D:\Repo\Inter-Role-Play Gamemode\sa-mp-0.2-plugin-sdk\IRP\Debug\IRPCore.exp
1> core.obj:错误LNK2001:未解析的外部符号“public:static class std::tr1::无序_map core::itemCache”(?)?itemCache@core@@2V?$无序_map@HUitem@@V$hash@H@std@@U?$equal_to@H@3@V?$allocator@U?$pair@$$CBHUitem@@@std@@@3@@tr1@std@@(A)
1> main.obj:错误LNK2001:未解析的外部符号“public:static class std::tr1::无序_map core::itemCache”(?)?itemCache@core@@2V?$无序_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:致命错误LNK1120:1未解析外部
下面是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 : "";
} 
#包括
#包括
#包括“core.h”
core::core(void)
{
}
核心::~核心(无效)
{
}
void core::Item_Insert(int-uid,Item-Item)
{
core::itemCache.insert(std::make_pair(uid,Item));
返回;
}
std::string core::convertNativeStringToString(AMX*AMX,单元格输入)
{
char*string=NULL;
amx_StrParam(amx,输入,字符串);
返回字符串?字符串:“”;
} 
我应该链接更多的LIB吗

提前谢谢

编辑:这里是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:
};
类核心
{
公众:
静态std::无序映射itemCache;
芯(空);
~core(void);
静态无效项目\插入(内部uid,项目);
静态std::字符串convertNativeStringToString(AMX*AMX,单元格输入);
私人:
};

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

正如@Pete Becker所说,将其放在cpp的顶部:

std::unordered_map<int, item> core::itemCache;
std::无序映射核心::itemCache;
除了

static std::unordered_map<int, item> itemCache;
static std::无序映射itemCache;

已经在.h.

中了,但是他显示了他定义它的源文件,并且他包含了一个可能声明该类的core.h。我认为他的itemcache不是静态的,他没有实例化它。但是我不确定,我对这个错误很好奇。@JonathanCruz:我看到了一个源文件,但我没有看到它在任何地方被定义。他包括core.h,它可能声明了变量,但是全局/静态不应该在头中定义。类和结构项的声明是im core。h@Kacper-是的,我就是这么猜的。但是,您需要在源文件中定义静态数据成员。@Kacper-再一次:您在头文件中声明它(如core.h所示),并且必须在源文件中定义它。这意味着更改core.cpp。