Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling python modules with DEBUG defined on MSVC

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?

like image 830
DaedalusFall Avatar asked Aug 05 '09 22:08

DaedalusFall


People also ask

How do I debug a python code in Visual Studio?

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.

How do I run python in debug mode 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.

How do I debug a python program in Linux?

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().


3 Answers

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)

like image 95
Preet Sangha Avatar answered Oct 21 '22 09:10

Preet Sangha


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.

like image 23
Xunlei Avatar answered Oct 21 '22 08:10

Xunlei


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.

like image 31
d.Candela Avatar answered Oct 21 '22 07:10

d.Candela