[Distutils] DEF Files

Robert Kern kernr@ncifcrf.gov
Tue, 14 Sep 1999 17:32:08 -0400


"M.-A. Lemburg" wrote:
> 
> Anthony Pfrunder wrote:
> >
> > On Tue, 14 Sep 1999, Robert Kern wrote:
> >
> > > FWIW, I agree with David that requiring modifying the source of an
> > > extension is not a good thing.  It only adds a headache for people trying to port from *NIX to
> > > Windows (and we have enough to deal with,
> > > believe me), and it pollutes the code with weird MS extensions.
> > ... and weird unix only utilites such as sed [sorry, my Windows side speaking]
> 
> I don't really get your points here... you can stick all those
> weird symbols into macros and then forget about them.

For modules that will be written in the future, yes, we can insist that
all extensions use a macro like yours.  Python's code uses DL_IMPORT 
to do the same thing.  But since we can generate the DEF files so 
easily, we don't have to require any source code changes for 
already-existing modules.

> Writing...
> 
> #include "mxh.h"
> MX_EXPORT(void)
>      initmxODBC(void)
> {
> }
> 
> ...isn't all that bad and makes the intention pretty clear. Here's
> the contents of mxh.h:
> 
> /* Macro to "mark" a symbol for DLL export */
> 
> #if defined(_MSC_VER) && _MSC_VER > 850 /* MS VC++ 2.0 and up */
> # ifdef __cplusplus
> #   define MX_EXPORT(type) extern "C" type __declspec(dllexport)
> # else
> #   define MX_EXPORT(type) extern type __declspec(dllexport)
> # endif
> #elif defined(__WATCOMC__)
> #   define MX_EXPORT(type) extern type __export
> #else
> #   define MX_EXPORT(type) extern type
> #endif
> 
> /* Macro to "mark" a symbol for DLL import */
> 
> #if defined(__BORLANDC__)
> #   define MX_IMPORT(type) extern type __import
> #elif defined(_MSC_VER) && _MSC_VER > 850 /* MS VC++ 2.0 and up */
> # ifdef __cplusplus
> #   define MX_IMPORT(type) extern "C" type __declspec(dllimport)
> # else
> #   define MX_IMPORT(type) extern type __declspec(dllimport)
> # endif
> #else
> #   define MX_IMPORT(type) extern type
> #endif
>
> BTW, additions to support more compilers are always welcome.

You can add "|| defined(__MINGW32__)" to the lines with _MSC_VER.

> The above works for pretty much all Unix, Mac and Windows compilers
> people have used to compile my extensions, so I guess its pretty
> generic.
> 
> --
> Marc-Andre Lemburg

-- 
Robert Kern           |
----------------------|"In the fields of Hell where the grass grows high
This space            | Are the graves of dreams allowed to die."
intentionally         |           - Richard Harter
left blank.           |