I am using a module definition file (.def) in visual studio 2008 to selectively export symbols to generate an import library. According to the documentation on MSDN, adding the keyword DATA (or CONSTANT) 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.
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;
};
Consider the code above. I wish to export the variable xml so that it can be used over a dll boundary. When linking against the resulting import library, it requests the following symbol.
"public: static class Allocator * MemoryService::xml" (?xml@MemoryService@@2PAVAllocator@@A)
When the symbol is added to the module definition file without the DATA keyword, it recognizes the symbol but the code using the variables crashes. Linking against a import library that has the symbol annotated as DATA doesn't recognize the symbol and gives a (unresolved symbol) linker error instead.
EXPORTS
?xml@MemoryService@@2PAVAllocator@@A DATA
'dumpbin /exports' however list the output illustrated below. The resulting import library, evidently does export the name in question.
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
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?