Problems importing _sre w/VC7-compiled Python 2.1

David Aldridge daldridge at austin.rr.com
Sun May 19 09:26:01 EDT 2002


After more investigation, turns out init_sre() was NOT
__declspec(dllexport)!

_sre.c #includes "Python.h"
"Python.h" #includes "config.h"

config.h, starting at line 120, has the following:

#ifdef USE_DL_IMPORT
#define DL_IMPORT(RTYPE) __declspec(dllimport) RTYPE
#endif
#ifdef USE_DL_EXPORT
#define DL_IMPORT(RTYPE) __declspec(dllexport) RTYPE
#define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE
#endif

If I change it to be:

#ifdef USE_DL_IMPORT
#define DL_IMPORT(RTYPE) __declspec(dllimport) RTYPE
#define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE
#endif
#ifdef USE_DL_EXPORT
#define DL_IMPORT(RTYPE) __declspec(dllexport) RTYPE
#define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE
#endif

Everything works just peachy.  (Added the dllexport line if
USE_DL_IMPORT is defined).

Turns out since python/pythoncore is in a .DLL, the sre module wanted
to import its exports, and had USE_DL_IMPORT defined.  However, since
DL_EXPORT was not defined in the USE_DL_IMPORT block, later on in
Python.h (after it's done preprocessing config.h), DL_EXPORT(RTYPE) is
simply defined as RTYPE.  Oops -- no export of init_sre().

Thanks for the prod in the right direction ;-)
David

sjmachin at lexicon.net (John Machin) wrote in message news:<c76ff6fc.0205181617.7b529696 at posting.google.com>...
> "RoadRunner eNews" <audballio at yahoo.com> wrote in message news:<urxF8.92424$9F5.5507182 at typhoon.austin.rr.com>...
> > I've successfully built Python 2.1 with VC7, but I'm having a problem using
> > the resulting binaries, namely _sre.pyd (and _d.pyd).  Specifically, when I
> > attempt to 'import re', the result is a Traceback stating 'ImportError:
> > dynamic module does not define init function (init_sre)'.   Everything works
> > fine under VC6, and ...\modules\_sre.c definitely contains init_sre(), so it
> > has to be something VC7 related.
> > 
> 
> I'm not an MS VCn guru for any value of n. However, based on some
> trips through "DLL hell" with other compilers, here are some ideas
> that may help:
> 
> (1) Use the Dependency Walker or some other tool to examine the
> _sre.pyd itself to see that the entry point init_sre is actually there
> (and not _init_sre or something else), rather than relying on its
> presence in the source. Then you will know whether the problem is in
> the importer or the importee.
> 
> (2) If you haven't done so already, you should use the -v option when
> running Python, to display the names of the actual full paths for
> files that it is opening. However I can't recall whether you will get
> the path printed before the ImportError.
> 
> HTH,
> John



More information about the Python-list mailing list