【问题标题】:Loki's SmallObjAllocator of of memoryLoki 的 SmallObjAllocator 内存分配器
【发布时间】:2015-05-19 13:30:32
【问题描述】:
#include "stdafx.h"                            //In order to use Visual C++

#include <iostream>
#include <Loki\SmallObj.h>                    //The header file to manage
                                              // smalls objects allocator

class MySmallObj : public Loki::SmallObjAllocator    //inherit from the base
                                                     //class SmallObjAllocator 
{
public:
    MySmallObj():SmallObjAllocator(sizeof(char), sizeof(long),0){};
};

int _tmain(int argc, _TCHAR* argv[])
{
    MySmallObj * premier = new MySmallObj;                                                      //declaring my object derived from smallobjallcator
    char * myChar = static_cast<char*>( premier->Allocate(1, true));            //calling allocate from my object and conveting the void pointer to char*
    premier.Deallocate(myChar, 1);

    return 0;
}

loki 库本质上使用 c++ 中的泛型编程 我已经使用内存的小对象分配器(Loki::SmallObjAllocator)获得了代码 我正在使用 Visual C++ 2010

我收到这些错误:

  >  MyLoki.cpp
1>MyLoki.obj : error LNK2019: unresolved external symbol "public: void __thiscall Loki::SmallObjAllocator::Deallocate(void *,unsigned int)" (?Deallocate@SmallObjAllocator@Loki@@QAEXPAXI@Z) referenced in function _wmain
1>MyLoki.obj : error LNK2019: unresolved external symbol "public: void * __thiscall Loki::SmallObjAllocator::Allocate(unsigned int,bool)" (?Allocate@SmallObjAllocator@Loki@@QAEPAXI_N@Z) referenced in function _wmain
1>MyLoki.obj : error LNK2019: unresolved external symbol "protected: __thiscall Loki::SmallObjAllocator::SmallObjAllocator(unsigned int,unsigned int,unsigned int)" (??0SmallObjAllocator@Loki@@IAE@III@Z) referenced in function "public: __thiscall MySmallObj::MySmallObj(void)" (??0MySmallObj@@QAE@XZ)

【问题讨论】:

  • 您是否添加了配置以链接到库?
  • 试图将此标记为“什么是未解决的外部符号错误以及如何解决它”的副本..
  • 您的第一个问题@EdChum 是想知道我是否已将库链接到编译器?是的,我做到了。
  • 它不是重复的,因为我使用 Loki::SmallObjAllocator 搜索了互联网上的(数周)示例,但它们不一致或不明确。 (我只找到了提升之一: boost::object_pool )@MarcoA。

标签: c++ loki


【解决方案1】:

我已经找到了第一个问题的答案。

#include "stdafx.h"                            //In order to use Visual C++

#include <iostream>
#include <Loki\SmallObj.h>                    //The header file to manage
                                              // smalls objects allocator

class MySmallObj : public Loki::SmallObjAllocator    //inherit from the base
                                                     //class SmallObjAllocator
{
public:
    MySmallObj():SmallObjAllocator(sizeof(char), sizeof(long),1){};  //the chunkSize < maxObjsize
};
int _tmain(int argc, _TCHAR* argv[])
{
    MySmallObj * premier = new MySmallObj;                                                      //declaring my object derived from smallobjallcator
    char * myChar = static_cast<char*>( premier->Allocate(1, true));            //calling allocate from my object and conveting the void pointer to char*
    premier->Deallocate(myChar, 1);

    return 0;
}

多重错误

未解析的外部符号

是因为 Loki 的 SmallObj.cpp 没有包含在项目中

例如 Loki::SmallObjAllocator、Loki::SmallObject here

【讨论】:

    猜你喜欢
    • 2021-08-19
    • 2011-02-12
    • 2010-11-08
    • 2011-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-08
    • 2010-10-24
    相关资源
    最近更新 更多