<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";
        color:black;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:"Courier New";
        color:black;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style></head><body lang=EN-US link=blue vlink="#954F72"><div class=WordSection1><p class=MsoNormal><span lang=EN-AU>You don’t have to use distutils to build your extension, and if you want anything more complex than a release build you probably should build it yourself.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-AU><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-AU>All you need is the right include and lib directories when compiling/linking, set the output extension to pyd instead of dll, and use /MD when targeting python.exe and /MDd when targeting python_d.exe. You can use whatever /Ox options you like regardless of your target. There’s nothing really special about what the build tools do, other than being readily available on most Python distros.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-AU><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-AU>Since you're on Windows, why not have a look at Visual Studio 2017? The Python workload has a native development option that includes a template for building/debugging an extension module with these options already configured (<a href="https://docs.microsoft.com/en-us/visualstudio/python/cpp-and-python">https://docs.microsoft.com/en-us/visualstudio/python/cpp-and-python</a>), and the debugger supports stepping through both Python and C code simultaneously (<a href="https://docs.microsoft.com/en-us/visualstudio/python/debugging-mixed-mode">https://docs.microsoft.com/en-us/visualstudio/python/debugging-mixed-mode</a>). It might make your life a little easier.</span></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Top-posted from my Windows phone</p><p class=MsoNormal><o:p> </o:p></p><div style='mso-element:para-border-div;border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal style='border:none;padding:0in'><b>From: </b><a href="mailto:vano@mail.mipt.ru">Ivan Pozdeev</a><br><b>Sent: </b>Wednesday, January 10, 2018 5:47<br><b>To: </b><a href="mailto:steve.dower@python.org">Steve Dower</a>; <a href="mailto:python-ideas@python.org">python-ideas@python.org</a><br><b>Subject: </b>Re: [Python-ideas] Allow to compile debug extension againstreleasePython in Windows</p></div><p class=MsoNormal><o:p> </o:p></p><p>On 09.01.2018 21:35, Ivan Pozdeev via Python-ideas wrote:</p><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><p class=MsoNormal><span style='color:black'>On 08.01.2018 0:11, Steve Dower wrote:<br><br><o:p></o:p></span></p><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><p class=MsoNormal><span lang=EN-AU style='color:black'>It’s not a good idea. You end up with two different C runtimes in memory that cannot communicate, and many things will not work properly.</span><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><span lang=EN-AU style='color:black'> </span><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><span lang=EN-AU style='color:black'>If you compile your debug build extension with the non-debug CRT (/MD rather than /MDd) you will lose asserts, but otherwise it will work fine and the quoted code picks the release lib.</span><span style='color:black'><o:p></o:p></span></p></blockquote><p class=MsoNormal><span style='color:black'>Distutils' designers seem to have thought differently.<br>Whether the extension is linked against pythonxx_d.lib is governed by the --debug switch to the `build' command rather than the type of the running Python. Compiler optimization flags and /MD(d) are inserted according to it, too.<br><br>As a consequence,<br>* I cannot install an extension into debug Python at all 'cuz `bdist_*' and `install' commands don't support --debug and invoke `debug' internally without it.<o:p></o:p></span></p></blockquote><p class=MsoNormal><span style='color:black'>I meant "invoke `build' internally without it." , sorry.<br><br>This kafkaesque "you cannot do this because you cannot do this" is taking its toll on me...<br><br><o:p></o:p></span></p><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><p class=MsoNormal><span style='color:black'>* Neither can I compile an extension for release Python without optimizations.<br><br>I'm at a loss here. Either I'm missing something, or with the current build system, it's impossible to debug extensions!<br><br><o:p></o:p></span></p><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><p class=MsoNormal><span lang=EN-AU style='color:black'> </span><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><span lang=EN-AU style='color:black'>Or if you like, when you install Python 3.5 or later there are advanced options to install debug symbols and binaries. You can use a proper debug build against the debug binaries (python_d.exe).</span><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><span lang=EN-AU style='color:black'> </span><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><span lang=EN-AU style='color:black'>Cheers,</span><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><span lang=EN-AU style='color:black'>Steve</span><span style='color:black'><o:p></o:p></span></p><p class=MsoNormal><span style='color:black'> <o:p></o:p></span></p><p class=MsoNormal><span style='color:black'>Top-posted from my Windows phone<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'> <o:p></o:p></span></p><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b><span style='color:black'>From: </span></b><span style='color:black'><a href="mailto:python-ideas@python.org">Ivan Pozdeev via Python-ideas</a><br><b>Sent: </b>Saturday, December 30, 2017 13:01<br><b>To: </b><a href="mailto:python-ideas@python.org">python-ideas@python.org</a><br><b>Subject: </b>[Python-ideas] Allow to compile debug extension against releasePython in Windows<o:p></o:p></span></p></div><p class=MsoNormal><span style='color:black'> <o:p></o:p></span></p><p class=MsoNormal><span style='color:black'>The Windows version of pyconfig.h has the following construct:<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'> <o:p></o:p></span></p><p class=MsoNormal><span style='color:black'>    if defined(_DEBUG)<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'>           pragma comment(lib,"python37_d.lib")<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'>    elif defined(Py_LIMITED_API)<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'>           pragma comment(lib,"python3.lib")<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'>    else<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'>           pragma comment(lib,"python37.lib")<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'>    endif /* _DEBUG */<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'> <o:p></o:p></span></p><p class=MsoNormal><span style='color:black'>which fails the compilation of a debug version of an extension. Making <o:p></o:p></span></p><p class=MsoNormal><span style='color:black'>debugging it... difficult.<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'> <o:p></o:p></span></p><p class=MsoNormal><span style='color:black'>Perhaps we could define some other constant?<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'> <o:p></o:p></span></p><p class=MsoNormal><span style='color:black'>I'm not sure whether such compilation is a good idea in general, so <o:p></o:p></span></p><p class=MsoNormal><span style='color:black'>asking here at first.<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'> <o:p></o:p></span></p><p class=MsoNormal><span style='color:black'>-- <o:p></o:p></span></p><p class=MsoNormal><span style='color:black'>Regards,<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'>Ivan<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'> <o:p></o:p></span></p><p class=MsoNormal><span style='color:black'>_______________________________________________<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'>Python-ideas mailing list<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'><a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><o:p></o:p></span></p><p class=MsoNormal><span style='color:black'><a href="https://mail.python.org/mailman/listinfo/python-ideas">https://mail.python.org/mailman/listinfo/python-ideas</a><o:p></o:p></span></p><p class=MsoNormal><span style='color:black'>Code of Conduct: <a href="http://python.org/psf/codeofconduct/">http://python.org/psf/codeofconduct/</a><o:p></o:p></span></p><p class=MsoNormal><span style='color:black'> <o:p></o:p></span></p></blockquote><p class=MsoNormal><span style='color:black'><br><br><o:p></o:p></span></p><pre>-- </pre><pre>Regards,</pre><pre>Ivan</pre><p class=MsoNormal><span style='color:black'><br><br><br><o:p></o:p></span></p><pre>_______________________________________________</pre><pre>Python-ideas mailing list</pre><pre><a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a></pre><pre><a href="https://mail.python.org/mailman/listinfo/python-ideas">https://mail.python.org/mailman/listinfo/python-ideas</a></pre><pre>Code of Conduct: <a href="http://python.org/psf/codeofconduct/">http://python.org/psf/codeofconduct/</a></pre></blockquote><p class=MsoNormal><span style='color:black'><br><br><o:p></o:p></span></p><pre>-- </pre><pre>Regards,</pre><pre>Ivan</pre><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New";color:black'><o:p> </o:p></span></p></div></body></html>