This is the mail archive of the cygwin@cygwin.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]

Re: dll-helpers


This is really a "how to build dll's" question and belongs on the cygwin 
list, not private mail.  For your convenience, I've copied this message 
to the list and set the Reply-To; appropriately.

Jason Moxham wrote:

> Using the latest cygwin I can compile and run the "c" version of
> dllhelpers-0.2.7 , but what I'm having trouble  with is , if my dll
> contains referances  to varibles/fns  in the main exe or another dll
> then I get undefined referances when I try to compile my dll


Right.  you can't do that on windows.  DLLs (unlike unix shared 
libraries) are not allowed to have any unresolved symbols.  Thus, you 
can't have forward references from the DLL to a client executable.

There are two ways to proceed:

1) put the "common" data items in a second DLL that can be built 
independently of the first DLL and the executable.  Then, when building 
the original DLL, link against this second one.  When building the 
executable, link against both DLLs.

or

2) Create hook functions in your DLL to set a DLL-internal pointer to 
point to your exe's variable.  Within the DLL, only use the pointer in 
your operations.

e.g.

DLL:
int * ext_data;
void set_ext_data(int * c) {ext_data = c};
In dll, use *ext_data.

client exe:
int data;
set_ext_data(&data);
in client, use data.

--Chuck


> 
> for example
> 
> add to usedll.c  (not in main fn)
> 
> int jayglob;
> 
> 
> 
> add to cdll.c 
> 
> int jay(void){return jayglob;}
> 
> 
> add to cdll.h
> 
> int	jay(void);
> extern int jayglob;
> 
> 
> then when I try to compile cygcdll.dll I get undefined referances to
> jayglob
> 
> 
> 
> Of course under linux , no problems



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


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