This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: exporting structs from DLL using mingw32/egcs 1.1 -- doesn't work
- To: "Ron Aaron" <ron at mossbayeng dot com>
- Subject: Re: exporting structs from DLL using mingw32/egcs 1.1 -- doesn't work
- From: Mumit Khan <khan at xraylith dot wisc dot edu>
- Date: Wed, 21 Oct 1998 20:10:25 -0500
- Cc: egcs at cygnus dot com, gnu-win32 at cygnus dot com
"Ron Aaron" <ron@mossbayeng.com> writes:
> I am trying to export data from a DLL, where the variable in question is a
> struct.
>
> So I have in my DLL:
> __declspec(dllexport) struct joebob myvar;
>
> and in the file which uses is:
> __declspec(dllimport) struct joebob myvar;
>
> But the mingw32/egcs 1.1 compiler complains that there is a declaration
> conflict between the two.
>
> Now, if I change this to 'struct joebob * myvar' in both places, it works
> just fine.
>
> My problem is that this is someone else's code, and it compiles and runs
> fine with the Borland C compiler, and changing the dozen or so instances of
> this sort of thing would involve a *lot* of #ifdef's in the code, which I
> studiously wish to avoid.
>
> Is this an issue which will be repaired? That is, will I be able to export
> data larger than int's at some point (or how can I do it now)?
The code is not correct.
MSVC issues a warning instead of an error:
test.c(6) : warning C4273: 'myvar' : inconsistent dll linkage.
dllexport assumed.
which IMO is simply dangerous. Much better to flag it as an error
instead. I might go with MSVC behaviour of issuing a warning, and
error when -pedantic, for next release however.
Win32 DLLs are grotesque to use, and even more grotesque to implement
correctly; all the special redefinition rules don't help matters
mcuh. It's better to just code correctly.
See my dllhelpers package on how to do this portably that works with
all the win32 compilers.
http://www.xraylith.wisc.edu/~khan/software/gnu-win32/
Regards,
Mumit