模块定义文件数据导出

时间:2014-02-22 09:46:38

标签: c++ visual-studio-2008 dll linker dumpbin

我在visual studio 2008中使用模块定义文件(.def)来选择性地导出符号以生成导入库。根据MSDN上的documentation,在符号名称后添加关键字 DATA (或 CONSTANT )可以创建数据声明。关于这一点,我遇到了一些问题。如果有人可以解决下面列出的问题,我将不胜感激。

class Allocator
{
public:
    static const int size_not_tracked = 0xFFFFFFFF;
    virtual void *allocate(size_t size, size_t align) = 0;
    virtual void *reallocate(void* ptr, size_t size, size_t align) = 0;
    virtual void deallocate(void *p) = 0;
    virtual size_t allocated_size(void *p) = 0;
    virtual size_t allocated() = 0;
};

class MemoryService
{
public:
    static Allocator* GetProcessDefault();
    static Allocator* GetProcessHeap();
    static Allocator* GetNamedHeap(const char* name, bool tracked, bool logged);    
    static Allocator* xml;
};

考虑上面的代码。我希望导出变量 xml ,以便可以在dll边界上使用它。链接到生成的导入库时,它会请求以下符号。

  

“public:static class Allocator * MemoryService :: xml”   (?XML @ @@ MemoryService @@ 2PAVAllocator A)

当符号添加到模块定义文件而不 DATA 关键字时,它会识别符号,但代码会使用变量崩溃。链接具有注释为 DATA 的符号的导入库无法识别该符号,而是提供(未解析的符号)链接器错误。

EXPORTS
?xml@MemoryService@@2PAVAllocator@@A DATA

'dumpbin / exports'但是列出下面显示的输出。生成的导入库显然确实导出了有问题的名称。

Microsoft (R) COFF/PE Dumper Version 9.00.30729.01
Copyright (C) Microsoft Corporation.  All rights reserved.

Dump of file xxxxx.lib
File Type: LIBRARY    
     Exports    
       ordinal    name    
                  ....
                  ?xml@MemoryService@@2PAVAllocator@@A (public: static class Allocator * MemoryService::xml)
                  ....    
  Summary    
          CF .debug$S
          14 .idata$2
          14 .idata$3
           4 .idata$4
           4 .idata$5
          10 .idata$6

链接器无法识别符号是否有原因?是否可以进行任何修改以使图示的代码有效?

0 个答案:

没有答案