This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: [Windows] Unable to link with Python in debug configuration
Type: compile error Stage:
Components: Build, Library (Lib), Windows Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: sgallou, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2015-02-04 19:45 by sgallou, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (7)
msg235397 - (view) Author: Sébastien Gallou (sgallou) Date: 2015-02-04 19:45
Hi all,

I installed Python (2.7.9) as binaries under Windows. I have trouble trying to compile my application embedding Python, in debug configuration. I have exactly the same problem as described here :
http://www.cmake.org/pipermail/cmake/2013-January/053125.html

The include file python.h selects automaticaly the library file to link with, but python27_d.lib (needed in debug configuration) is not provided by the installer.

I don't find if this issue was already supported.

Thanks,
Sébastien Gallou
msg235398 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2015-02-04 19:47
It's not supported. You'll need to get the Python 2.7 source code and rebuild the binaries under Debug.

Python 3.5 will probably have the option to download and install debug versions of the binaries, but Python 2.7 won't be getting this.
msg235399 - (view) Author: Sébastien Gallou (sgallou) Date: 2015-02-04 19:52
Thanks Steve for your quick answer.
It's now clear for me.

I will then apply this workaround :

#ifdef PYTHON_USE_SOURCES
   #include <Python.h>
#else
   #if defined WIN32 && defined _DEBUG
      #undef _DEBUG // Undef _DEBUG to use only release version of Python.lib. The debug version of Python.lib is not provided with the Windows installer version (https://www.python.org/downloads/windows/)
      #include <Python.h>
      #define _DEBUG
   #else
      #include <Python.h>
   #endif
#endif // PYTHON_USE_SOURCES

Sébastien Gallou
msg235402 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2015-02-04 20:32
You'll also need to change your project to use the release version of the C Runtime library and undefine _DEBUG throughout, otherwise you'll get conflicts in things like memory allocators and alignment. It's not quite as simple as choosing another lib.
msg235403 - (view) Author: Sébastien Gallou (sgallou) Date: 2015-02-04 20:58
So there is no mean to build my application in debug mode without rebuilding all Python ?
msg235407 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2015-02-04 21:51
Afraid not. The closest you can get is building in Release with full debug symbols and no optimisations, which should al lest get you decent debugging. However, you won't get the extra memory check patterns or assertions throughout your code.
msg235408 - (view) Author: Sébastien Gallou (sgallou) Date: 2015-02-04 21:53
Thanks Steve,

I will try to build it (hope it will not be too difficult...). If I don't success, I will use your solution.
History
Date User Action Args
2022-04-11 14:58:12adminsetgithub: 67582
2015-02-04 21:53:38sgallousetmessages: + msg235408
2015-02-04 21:51:02steve.dowersetmessages: + msg235407
2015-02-04 20:58:02sgallousetmessages: + msg235403
2015-02-04 20:32:40steve.dowersetmessages: + msg235402
2015-02-04 19:52:33sgallousetstatus: open -> closed
resolution: not a bug
messages: + msg235399
2015-02-04 19:47:36steve.dowersetmessages: + msg235398
2015-02-04 19:45:04sgalloucreate