Mail Archives: cygwin/2001/05/14/09:27:11
------=_NextPart_000_002D_01C0DC89.AA541000
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 8bit
> -----Ursprüngliche Nachricht-----
> Von: cygwin-owner AT sources DOT redhat DOT com
> [mailto:cygwin-owner AT sources DOT redhat DOT com]Im Auftrag von Andrej Borsenkow
> Gesendet am: Sonntag, 13. Mai 2001 11:43
> An: Jesper Eskilson
> Cc: Alan Hourihane; cygwin AT cygwin DOT com
> Betreff: Re: function pointers & DLL's
>
> On Sun, 13 May 2001, Jesper Eskilson wrote:
>
> > On Sun, 6 May 2001, Alan Hourihane wrote:
> >
> > > Everything works fine. But what I'm trying to do is find a
> way at the linker
> > > stage that negates me having to make these __declspec
> statements. Is there
> > > any way this is possible ?
> >
> > For VC++ (at least) __declspec(dllimport) is purely optional and never
> > required. The only this they do is to enable the compiler to skip an
> > indirection in the jump and generate a slightly more efficient jump.
> >
>
> For GCC (at least :-) __declspec(dllimport) is optional for functions but
> is mandatory for variables. The side-effect of the above is, that function
> address is no more static and cannot be used as static initializer, e.g.
> in function dispatch table like
>
That's not right. Paul Sokolvsky has written an ld patch named auto-import
initial for mingw, which is adapted to cygwin. Look into the appended files.
If you like, you can have this patched ld by mail and try it out.
Regards
Ralf Habacker
EMail: Ralf AT habacker DOT de
Ralf DOT Habacker AT saght DOT tessag DOT com
------=_NextPart_000_002D_01C0DC89.AA541000
Content-Type: application/octet-stream;
name="dll.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="dll.c"
int var=123;
int foo = 121;
#include <stdio.h>
void print_var()
{
printf("Dll sees var=%d\n",var);
}
void print_foo()
{
printf("Dll sees foo=%d\n",foo);
}
void (*func_ptr)() = print_foo;
------=_NextPart_000_002D_01C0DC89.AA541000
Content-Type: application/octet-stream;
name="Makefile"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="Makefile"
CC=gcc
LDFLAGS=-v -Wl,-Map,client.map #-Wl,--disable-auto-import
LDLIBS=-L. -ldll
all: dll.dll client
dll.dll: dll.o
$(CC) --shared $^ -o $@ -Wl,--out-implib,libdll.a
client: client.o
clean:
rm -f *.o *.dll *.exe *.map *.a
------=_NextPart_000_002D_01C0DC89.AA541000
Content-Type: application/octet-stream;
name="client.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="client.c"
#include <stdio.h>
extern int var;
extern void (*func_ptr)();
extern void print_var();
extern void print_foo();
extern int foo;
typedef struct {
int *var;
void (*func_ptr)();
} TEST;
TEST xyz = { &var, print_var };
main()
{
print_var();
printf("we see var=%d\n",var);
printf("setting var=456\n");
var=456;
print_var();
printf("we see var=%d\n\n",var);
var=90;
print_var();
printf("we see var=%d\n\n",var);
print_foo();
printf("we see foo=%d\n",foo);
printf("setting foo=19\n");
foo=19;
print_foo();
printf("we see foo=%d\n\n",foo);
fflush(stdout);
printf("Calling dllimported function pointer:\n");
func_ptr();
printf("Calling functions using global structure\n");
xyz.func_ptr();
*xyz.var = 40;
xyz.func_ptr();
}
------=_NextPart_000_002D_01C0DC89.AA541000
Content-Type: text/plain; charset=us-ascii
--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple
------=_NextPart_000_002D_01C0DC89.AA541000--
- Raw text -