dllimport and initialization issue

Kai Tietz ktietz70 at googlemail.com
Thu Jul 22 19:30:53 UTC 2010


2010/7/22 Michael Cronenworth <mike at cchtml.com>:
> This code compiles with no errors or warnings:
> __attribute__ ((dllimport)) int _fmode;
>
> This code does not compile:
> __attribute__ ((dllimport)) int _fmode = _O_BINARY;
> foo.c:123: error: variable '_fmode' definition is marked dllimport
> foo.c:123: warning: '_fmode' redeclared without dllimport attribute:
> previous dllimport ignored
>
> Am I doing something horribly wrong or is this a gcc bug?

Well, indeed you are doing here something wrong. As you declare global
variable '_fmode' you have to use here instead of
__declspec(dllimport) the attribute __declspec(dllexport) . The
__declspec(dllimport) means for the compiler that the symbol '_fmode'
has to imported from a different DLL into your app and by this you see
those warnings.
Btw what exactly you want to do here with _fmode? It is part of the C-runtime.

Kai

-- 
|  (\_/) This is Bunny. Copy and paste
| (='.'=) Bunny into your signature to help
| (")_(") him gain world domination


More information about the mingw mailing list