将 python 与 c++ 接口

Interfacing python with c++

本文关键字:接口 c++ python      更新时间:2023-10-16

我正在尝试将python与C++接口。我正在使用Visual Studio Express 2012。我还有一个 enthought python 2.7 发行版。当我尝试使用以下代码在 Win 32 上构建版本时:

#include "stdafx.h"
#include "C:/Python27/include/Python.h"
#include "C:/Python27/Lib/site-packages/numpy/core/include/numpy/arrayobject.h"
using namespace std;

int main( int argc, char* argv[] )
{  
   int x = 1;
   PyObject *mod1;
   Py_Initialize();
   return 0;
}

我收到以下错误:

Error   1   error LNK2001: unresolved external symbol __imp__Py_Initialize

请帮忙,任何想法都非常欢迎。

应将C:Python27libs添加到库路径中,并将python27.lib添加到依赖项中。

为此:

Go to project properties -> Configuration properties -> Linker.
Go to ->General and set the "Additional Library directories"

在此字段中,您可以添加C:Python27libs

然后:

Go to Linker -> Input and set the "Additional Dependencies"

在此字段中,您可以添加python27.lib

此外,您还应该将C:Python27include添加到包含目录中,然后执行以下操作:

#include <Python.h>

我认为您尝试将 64 位 python 库链接到 32 位应用程序