[Python-Dev] distutils.cygwinccompiler: invalid executable for interpreters
Alexey Borzenkov
snaury at gmail.com
Thu Jan 10 23:33:51 CET 2008
Hi everyone,
Some time ago I've stumbled upon a problem with compiling py2exe with
mingw: it resulted in invalid executable run.exe. At first I dismissed
it as some very strange problem, but recently I decided to look into
it again and found that the reason for this is a .def file, supplied
during compilation, that causes linker to produce executable with
IMAGE_FILE_DLL in its PE Header Characteristics field, and operating
system refuses to execute it.
I traced this problem to the following block in distutils/cygwinccompiler.py:
# handle export symbols by creating a def-file
# with executables this only works with gcc/ld as linker
if ((export_symbols is not None) and
(target_desc != self.EXECUTABLE or self.linker_dll == "gcc")):
Removing 'or self.linker_dll == "gcc"' obviously helps. To me this
sounds like a bug (introduced in revision 17747 on trunk, more that 7
years old!), but I was wondering if there's any logic behind
generating a .def file for the executable (sidenote: look at
distutils/emxccompiler.py where .def file is generated for executables
only). To me it's very unlikely that anyone *ever* needs to export
symbols from an executable (I'm not even sure if it can work as
intended on Windows). Even then, if there's anyone at all who needs
such a machinery (again, what for?), at the very least it shouldn't
produce "LIBRARY" line. As minimal change as this:
# Generate .def file
contents = [
"LIBRARY %s" % os.path.basename(output_filename),
"EXPORTS"]
if target_desc == self.EXECUTABLE:
contents.pop(0)
Did the trick (generated executable runs fine).
Is anyone interested in a bug report for this? Also, is there any
chance that if there is interest it could end up in release25-maint?
Best regards,
Alexey.
More information about the Python-Dev
mailing list