comparison setup.py @ 32782:9a4adc76c88a

setup: avoid linker warnings on Windows about multiple export specifications The PyMODINIT_FUNC macro contains __declspec(dllexport), and then the build process adds an "/EXPORT func" to the command line. The 64-bit linker flags this [1]. Everything except zstd.c and bser.c are covered by redefining the macro in util.h [2]. These modules aren't built with util.h in the #include path, so the redefining hack would have to be open coded two more times. After seeing that extra_linker_flags didn't work, I couldn't find anything authoritative indicating why, though I did see an offhand comment on SO that CFLAGS is also ignored on Windows. I also don't fully understand the interaction between msvccompiler and msvc9compiler- I first subclassed the latter, but it isn't used when building with VS2008. I know the camelcase naming isn't the standard, but the HackedMingw32CCompiler class above it was introduced 5 years ago (and I think the current style was in place by then), so I assume that there's some reason for it. [1] https://support.microsoft.com/en-us/help/835326/you-receive-an-lnk4197-error-in-the-64-bit-version-of-the-visual-c-compiler [2] https://bugs.python.org/issue9709#msg120859
author Matt Harbison <matt_harbison@yahoo.com>
date Fri, 09 Jun 2017 22:15:53 -0400
parents 6c4b58422974
children 19b0fd4b5570
comparison
equal deleted inserted replaced
32781:448fc659a430 32782:9a4adc76c88a
701 # the cygwinccompiler package is not available on some Python 701 # the cygwinccompiler package is not available on some Python
702 # distributions like the ones from the optware project for Synology 702 # distributions like the ones from the optware project for Synology
703 # DiskStation boxes 703 # DiskStation boxes
704 class HackedMingw32CCompiler(object): 704 class HackedMingw32CCompiler(object):
705 pass 705 pass
706
707 if os.name == 'nt':
708 # Allow compiler/linker flags to be added to Visual Studio builds. Passing
709 # extra_link_args to distutils.extensions.Extension() doesn't have any
710 # effect.
711 from distutils import msvccompiler
712
713 compiler = msvccompiler.MSVCCompiler
714
715 class HackedMSVCCompiler(msvccompiler.MSVCCompiler):
716 def initialize(self):
717 compiler.initialize(self)
718 # "warning LNK4197: export 'func' specified multiple times"
719 self.ldflags_shared.append('/ignore:4197')
720 self.ldflags_shared_debug.append('/ignore:4197')
721
722 msvccompiler.MSVCCompiler = HackedMSVCCompiler
706 723
707 packagedata = {'mercurial': ['locale/*/LC_MESSAGES/hg.mo', 724 packagedata = {'mercurial': ['locale/*/LC_MESSAGES/hg.mo',
708 'help/*.txt', 725 'help/*.txt',
709 'help/internals/*.txt', 726 'help/internals/*.txt',
710 'default.d/*.rc', 727 'default.d/*.rc',