diff --git a/src/PythonQtPythonInclude.h b/src/PythonQtPythonInclude.h index dcf281406..673db874f 100644 --- a/src/PythonQtPythonInclude.h +++ b/src/PythonQtPythonInclude.h @@ -56,19 +56,53 @@ # include # endif +// +// Use the real python debugging library if it is provided. +// Otherwise use the "documented" trick involving checking for _DEBUG +// and undefined that symbol while we include Python headers. +// Update: this method does not fool Microsoft Visual C++ 8 anymore; two +// of its header files (crtdefs.h and use_ansi.h) check if _DEBUG was set +// or not, and set flags accordingly (_CRT_MANIFEST_RETAIL, +// _CRT_MANIFEST_DEBUG, _CRT_MANIFEST_INCONSISTENT). The next time the +// check is performed in the same compilation unit, and the flags are found, +// and error is triggered. Let's prevent that by setting _CRT_NOFORCE_MANIFEST. +// + // If PYTHONQT_USE_RELEASE_PYTHON_FALLBACK is enabled, try to link // release Python DLL if it is available by undefining _DEBUG while // including Python.h #if defined(PYTHONQT_USE_RELEASE_PYTHON_FALLBACK) && defined(_DEBUG) -#undef _DEBUG -#if defined(_MSC_VER) && _MSC_VER >= 1400 -#define _CRT_NOFORCE_MANIFEST 1 -#define _STL_NOFORCE_MANIFEST 1 +# define PYTHONQT_UNDEF_DEBUG +// Include these low level headers before undefing _DEBUG. Otherwise when doing +// a debug build against a release build of python the compiler will end up +// including these low level headers without DEBUG enabled, causing it to try +// and link release versions of this low level C api. +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# undef _DEBUG +# if defined(_MSC_VER) && _MSC_VER >= 1400 +# define _CRT_NOFORCE_MANIFEST 1 +# define _STL_NOFORCE_MANIFEST 1 +# endif #endif + #include -#define _DEBUG -#else -#include + +#ifdef PYTHONQT_UNDEF_DEBUG +# define _DEBUG #endif // By including Python.h on Linux truncate could have been defined (in unistd.h)