Python rather stupidly has a pragma directive in its include files that forces a link against python26_d.lib
when the DEBUG
preprocessor variable is defined. This is a problem because the python installer doesn't come with python26_d.lib
! So I can't build applications in MSVC in debug mode. If I temporarily #undef DEBUG
for just one file I get many complaints about inconsistent DLL linkage. If I change the pragma in pythons include file I get undefined references to various debug functions.
I have tried compiling my own version of python but its somehow different enough from the python that gets distributed that I can't use my modules with apps built with the vanilla version of python
Can anyone give me any advice on how to get round this?
If you're only interested in debugging a Python script, the simplest way is to select the down-arrow next to the run button on the editor and select Debug Python File in Terminal.
Directly use command python pdg-debug.py without -m pdb to run the code. The program will automatically break at the position of pdb. set_trace() and enter the pdb debugging environment. You can use the command p variable to view the variables or use the command c to continue to run.
Starting Python Debugger To start debugging within the program just insert import pdb, pdb. set_trace() commands. Run your script normally and execution will stop where we have introduced a breakpoint. So basically we are hard coding a breakpoint on a line below where we call set_trace().
From python list
As a workaround to the situation, try to copy the file python26.dll to python26_d.dll. (I'm not sure this will work; you say you are building a SWIG library in debug mode, and it's possible that SWIG will try to use features of the Python debugging version. If that's the case, you'll have no choice but to use the debugging version of Python.)
Edit: From comments:
You should also edit pyconfig.h and comment out the line "#define Py_DEBUG" (line 374)
After you comment out "#define Py_DEBUG" on line 332 and modify
# ifdef _DEBUG
# pragma comment(lib,"python26_d.lib")
# else
to
# ifdef _DEBUG
# pragma comment(lib,"python26.lib")
# else
you do not need to python26_d.lib anymore.
You can also go the other way: switch to «Release» and then debug it. you need to enable generation of debugging symbols info in project properties in compiler and linker prefs; MSDN here will tell you exactly what options you need to set to debug a release build.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With