Callbacks from shared libraries compiled with cygwin

Michael Spicar Michael.Spicar@carmen.se
Wed Sep 14 14:26:00 GMT 2005



Brian Dessent wrote:
> Michael Spicar wrote:
> 
> 
>>So I have two questions:
>>1) Is it possible at all to have callbacks like this?
>>2) If yes, must I have the import/export-lists?
> 
> 
> Yes, it's possible, but it's not considered great design.  You have to
> use __declspec(export) on the symbols in the main .exe, and then produce
> and import library for that .exe, and then link against that import
> library when you link the shared library.  But this will hard-code a
> dependence on the .exe name into the .dll, which means the .exe can
> never be renamed, and the dll cannot be used with any other .exe.
> 
> A better alternative is to factor out the variables/functions that you
> want to access from both the main .exe and the .dll into another common
> .dll that is imported by both.
> 
> Or change your API so that when main calls the function in the shared
> library it passes a function pointer as argument to the routine in main.
> 
> Brian

Thanks for your answers. And now it works. Initially I will choose the 
ugly solution and export all symbols. It doesn't matter right now, and 
the shared libraries I produce are anyway tight coupled to the application.

But I will use your advice to improve the solution later.

Michael


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list