views:

1102

answers:

5

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?

Thanks

+5  A: 

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)

Preet Sangha
Thanks, but it doesn't work. I also get the unresolved externals if I do that.
DaedalusFall
AHA! But it does work if you also edit pyconfig.h and comment out the line "#define Py_DEBUG" (line 374). Then everything links fine. Its still annoying that you have to modify the install rather than your own code, but it works. I've selected your answer as the chosen answer, but it would be nice if you updated your answer with this tip, in case other people come looking as they won't expect part of the solution to be in a comment. Thanks!
DaedalusFall
@DaedalusFall: Put that instruction in an answer, I want to upvote it! Had the exact same problem and your solution seems to work fine.
mizipzor
A: 

Can you create a debugging .lib file from the .dll via dumpbin http://support.microsoft.com/kb/131313?

Preet Sangha
No, there is Code that simply isn't in the non-debug library that python is trying to call when DEBUG is defined.
DaedalusFall
A: 

This works also when linking with static libraries. I made a copy of python26.lib, and renamed it python26_d.lib. I commented out the line #define PY_DEBUG in pyconfig.h. Also changed the pragma to "pragma comment(lib,"python26.lib")" on line 332. Voila! It worked.

Jive Dadson
+1  A: 

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.

d.Candela
A: 

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.

Xunlei