title: module definition file data exports
body: <p>I am using a module definition file (.def) in visual studio 2008 to selectively export symbols to generate an import library. According to the <a href="http://msdn.microsoft.com/en-us/library/hyx1zcd3.aspx" rel="nofollow">documentation</a> on MSDN, adding the keyword <em>DATA</em> (or <em>CONSTANT</em>) after the symbol-name allows one to create data declarations. Regarding this I am running into a few problems. I would appreciate it if somebody could shed should some light on the problem outlined below.</p>
  
  <pre><code>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;
  };
  </code></pre>
  
  <p>Consider the code above. I wish to export the variable <em>xml</em> so that it can be used over a dll boundary. When linking against the resulting import library, it requests the following symbol.</p>
  
  <blockquote>
    <p>"public: static class Allocator * MemoryService::xml"
    (?xml@MemoryService@@2PAVAllocator@@A)</p>
  </blockquote>
  
  <p>When the symbol is added to the module definition file <em>without</em> the <em>DATA</em> keyword, it recognizes the symbol but the code using the variables crashes. Linking against a import library that has the symbol annotated as <em>DATA</em> doesn't recognize the symbol and gives a (unresolved symbol) linker error instead.</p>
  
  <pre><code>EXPORTS
  ?xml@MemoryService@@2PAVAllocator@@A DATA
  </code></pre>
  
  <p><em>'dumpbin /exports'</em> however list the output illustrated below. The resulting import library, evidently does export the name in question. </p>
  
  <pre><code>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
  </code></pre>
  
  <p>Is there a reason why it the linker does not recognize the symbol? Are there any modifications possible which would permit the illustrated code to work?</p>