I am trying to #include <Python.h>
in my C++ code and when I go to compile my code I get this error:
fatal error LNK1104: cannot open file 'python33_d.lib'
I have tried to find python33_d.lib
on my computer to include in my linker dependencies, but I cannot find it. I have been able to find python33.lib
.
Where can I find the python33_d.lib
, or how can I resolve this issue?
Simple solution from the python bug tracker:
#ifdef _DEBUG
#undef _DEBUG
#include <python.h>
#define _DEBUG
#else
#include <python.h>
#endif
In the event that you need a debug version (as I do for work), it is possible to build the library yourself:
- Download the source tarball from http://www.python.org/download
- Extract the tarball (7zip will do the trick) and go into the resulting directory (should be something like Python-3.3.2).
- From the Python directory, go to the PCBuild folder. There are two important files here: readme.txt, which contains the instructions for building Python in Windows (even if it uses the UNIX line feed style...), and pcbuild.sln, which is the Visual Studio solution that builds Python.
- Open pcbuild.sln in Visual Studio. (I am assuming you are using Visual Studio 10; readme.txt contains specific instructions for older versions of Visual Studio.)
- Make sure Visual Studio is set to the "debug" configuration, and then build the solution for your appropriate architecture (x64 or Win32). You may get a few failed subprojects, but not all of them are necessary to build python33_d; by my count, 8 builds failed and I got a working .lib file anyway.
- You will find python33_d.lib and python33_d.dll in either the PCBuild folder (if building Win32) or the amd64 subfolder (if building x64).
*_d.lib
is used for debug builds. Switch to a release build instead.