This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Importing a variable from a DLL


The last time I posted to this list, I was asking a
question about a mysterious symbol,
_size_of_stack_reserve__, that gdb mentioned when my
program crashed.

Mumit Khan explained that this simply meant the code
had a bug elsewhere.  I looked and sure enough, I
found an extern variable that the DLL defines and the
main executable (main.exe) uses.

Declaring the variable __declspec (dllimport) in the
appropriate source file solved that.  But then I reran
the program and encountered the same problem with
another variable.

So I hunted for documentation on dllimport.  I found
only a few lines in full-man/info/* but more in the
MSVC documentation.

As I understand it, the situtation is this:  Suppose
that source file s1.cc used in main.exe references
extern variable v1 from the DLL.  Then s1.cc has to
declare v1 as __declspec (dllimport).  If s2.cc
through s20.cc also use v1, they must do likewise.

If this is true, I'll have to change about 140
declarations in the legacy application I'm porting. 
Each will need a macro, M, that expands to either
__declspec (dllimport) or to nothing.

These declarations appear in header files so I'll also
have to properly define M in every source file that
includes one of these headers.

Is there an easier way to do this?  For example, is
there a way to specify at link time that a variable is
imported?

I realize that the application has too many extern
variables but it's legacy and not mine to rewrite.

I also realize that fixups of this nature are harder
to do for variables than for functions but I thought I
should doublecheck anyway.

Thank you.
===
-- 
Opinions expressed above are not necessarily my employer's.
James M. Stern
ITG Inc.  Culver City, CA (213) 270-7955
__________________________________________________
Do You Yahoo!?
Bid and sell for free at http://auctions.yahoo.com


--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]