【问题标题】:Interfacing python with c++将python与c ++接口
【发布时间】:2013-09-13 05:45:21
【问题描述】:

我正在尝试将 python 与 C++ 接口。我正在使用 Visual Studio Express 2012。我也有一个经过深思熟虑的 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

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

【问题讨论】:

  • 呃...你尝试链接了吗?
  • 这是一个链接问题,您可以阅读已经提出的问题stackoverflow.com/questions/658879/…
  • 还将 Python 添加到您的包含路径中,而不是使用绝对路径
  • 对不起,我不知道你的意思是什么,我正在尝试构建它,它会自动链接它。由于这些错误,我无法构建它。我也尝试过那个帖子,但不清楚。如果我笨拙,我深表歉意,但请让我知道如何修复该错误以构建我的应用程序。谢谢。

标签: c++ python interface


【解决方案1】:

您应该将C:\Python27\libs 添加到您的库路径并将python27.lib 添加到您的依赖项。

为此:

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

在此字段中添加C:\Python27\libs

之后:

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

在此字段中添加python27.lib

您还应该将C:\Python27\include 添加到您的包含目录中,然后这样做:

#include <Python.h>

【讨论】:

  • 我做了上面的,也改成64位解决了我的问题。非常感谢。
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-15
    • 1970-01-01
    • 2013-03-30
    • 1970-01-01
    相关资源
    最近更新 更多