为什么不#include <Python.h>工作?

Cur*_*ous 12 c++ python wrapper visual-studio-2010

我正在尝试使用C++运行Python模块"#include <Python.h>",但是,在将项目的"Additional Include Dependencies"设置为"\ include"后,我在debuging时遇到以下错误,

LINK : fatal error LNK1104: cannot open file 'python27_d.lib'
Run Code Online (Sandbox Code Playgroud)

我读到我应该下载Python的开发版本,但是我没有找到它的链接,另外,我不需要将文件'python27_d.lib'复制到"libs"文件夹中吗?

请注意,我正在使用Anaconda的Python发行版.

提前致谢!

Kla*_*tte 25

我通常在调试版本中使用非调试Python库来避免这种情况.通常,这导致代码如下:

#ifdef _DEBUG
  #undef _DEBUG
  #include <Python.h>
  #define _DEBUG
#else
  #include <Python.h>
#endif
Run Code Online (Sandbox Code Playgroud)

在包含Python.h期间隐藏_DEBUG定义的位置.


Mar*_*ens 8

我对python知之甚少,但是消息表明python27_d.lib不存在,或者至少不存在链接器正在寻找它的地方.

您已经修复了编译器包含问题,现在使用Windows资源管理器找到python27_d.lib文件,并将该路径添加到Additional Library Dependencies路径.它位于Configuration - > Linker - > General - > Additional Library Directories下.

"_d"表示它是一个调试库,因此您需要一个用于Debug配置,而那个没有"_d"(可能)用于您的发布配置.


San*_*era 6

将 Visual Studio 置于发布模式而不是调试模式。