Importing a variable from a DLL

Paul Sokolovsky
Thu Aug 26 08:05:00 GMT 1999

Hello Mumit,

Mumit Khan <khan@xraylith.wisc.EDU> wrote:

MK> Paul Sokolovsky <> writes:
>>     But at least there might be achieved proper diagnostics of such
>> issues, if dlltool would correctly mark data symbols in def, that
>> implib would only contain __imp_<symbol> and not <symbol>, and we'd
>> get link error when linking with object which doesn't have
>> __declspec(dllimport) on that symbol, and not runtime segfaults,
>> as we have now.

MK> Sure, but it doesn't solve James' problem. If James could create the
MK> import libraries with all the data marked DATA, it would imply he
MK> already *knows* which these data items are!

    I am still feeling misunderstood. Let me go with it once again,
with examples.

    So, dlltool has ability to create implib from def - it's all nice
with it, it supports DATA, sure.

    But it has ability to dump all defined symbols into def file -
about this operation I am talking. So, suppose we have library of

extern int data;
int code();

int data;

int code()
  return 0;

    We compile a:
gcc -c a.c

    And now creating def of it:

dlltool a.o --export-all --output-def a.def

    What we now get is:
; G:\GCC-2.95\BIN\DLLTOOL.EXE --export-all --output-def a.def a.o
        data @ 1 ;
        code @ 2 ;
and it's bad! Suppose we'd get instead
; G:\GCC-2.95\BIN\DLLTOOL.EXE --export-all --output-def a.def a.o
        data @ 1 DATA;
        code @ 2 ;

    We create implib from that:

dlltool --def a.def --ouput-lib liba.a

And then compile client application:
#include "a.h"

int main()
When we link it

gcc client.o -la

What we get? Of course, "client.c: undefined reference to `data'"!
We now grepping, finding out that 'a.h' declares that 'data' and tag
it __declspec(dllimport). Repeat while needed.

   So, it doesn't solve problem we're talking about automagically, but
it defines clean procedure, which, while being incremental, will
converge fast. Much faster than having to catch segfaults for hours
and then having users complain of occasional ones for months, as we
have now.

MK> Regards,
MK> Mumit

Best regards,

Want to unsubscribe from this list?
Send a message to

More information about the Cygwin mailing list