如何解决Boost.Python中的__imp___Py_NoneStruct错误? [英] How to solve __imp___Py_NoneStruct Error in Boost.Python?

查看:321
本文介绍了如何解决Boost.Python中的__imp___Py_NoneStruct错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过Boost.Python链接C ++和Python.

I am trying to link C++ and Python with Boost.Python.

我有Visual Studio 2012 Express版本,Python 2.7和Boost 1.54.

I have Visual Studio 2012 Express Version, Python 2.7, and Boost 1.54.

我按照Boost官方网站的说明在计算机上安装Boost,这意味着我遵循了以下步骤:

I followed the instructions of Boost official website to install Boost on my machine, which means I followed these steps:

  1. 我下载了预编译的二进制文件并将其安装在C:\local\boost_1_54\.

我运行bjam b2 --build-dir=C:\local\boost_1_54 toolset=msvc11.0 --build-type=complete stage.

然后我在属性面板中进行了此类操作:

Then I had such operations in property panel:

  1. C:\local\boost_1_54\; C:\Python27\include;添加到C/C ++->常规"->附加包含目录".

  1. Add C:\local\boost_1_54\; C:\Python27\include; to C/C++->General->Additional Include Directories.

C:\local\boost_1_54\libs; C:\local\boost_1_54\lib64-msvc-11.0; C:Python27\libs;添加到Linker-> General-> Additional Library Directories.

Add C:\local\boost_1_54\libs; C:\local\boost_1_54\lib64-msvc-11.0; C:Python27\libs; to Linker->General->Additional Library Directories.

"Not Using Precompiled Headers"设置为C/C ++-> Precompiled Header-> Precompiled Header.

Set "Not Using Precompiled Headers" to C/C++->Precompiled Header->Precompiled Header.

然后我创建了一个空项目,其中的源代码非常简单,如下所示(我实际上尝试运行一个hello world示例,但必须减少代码以排除干扰):

And I created an empty project, in which the source code is very simple as follows (I actually tried to run a hello world example, but have had to reduce the codes in order to exclude distractions):

#include <boost/python.hpp>

int main()
{   
    return 0;
}

但是,当我尝试构建解决方案时,会弹出两个错误:

However, when I try to build the solution, two errors pop up as:

错误LNK2001:无法解析的外部符号__imp___Py_NoneStruct

错误LNK1120:1个未解决的外部

error LNK1120: 1 unresolved externals

我注释了#include <boost/python.hpp>行,然后错误消失了.

I commented the line #include <boost/python.hpp>, then the errors are gone.

让我感到困惑的是,我可以找到python.hpp放在它应该存在的文件夹中.

What confuses me is that I can find python.hpp is lying in the folder that it supposed to be.

我能知道我在做什么吗?

May I know what am I wrong?

================================================ ==========

==========================================================

我尝试在代码中使用#include <Python.h>.但这又引发了另一个错误

I've tried to use #include <Python.h> in the code. But it raise another error

错误LNK1104:无法打开文件'python27_d.lib'

error LNK1104: cannot open file 'python27_d.lib'

有人可以帮助我吗?

推荐答案

以下答案试图解决问题

error LNK1104: cannot open file 'python27_d.lib'

_d后缀表示它正在搜索该库的调试版本. Python安装是一个Release版本,因此您无法将Debug Project与之链接.

_d suffix means it is searching for a debug version of the library. The Python Installation is a Release build so you cannot link your Debug Project with it.

调试/发布

调试版本具有符号信息,并且通常未优化.此版本用于调试,其中零售版本"是发布的版本.

A Debug version has symbol information and generally not optimized. This version is used for debugging where as Retail Version is the version that is released.

如果要在调试模式"下构建项目,它将始终尝试与调试库链接.为了克服这个问题

If you are building your project in Debug Mode, it would always try to link with the debug libraries. To overcome this problem

  1. 创建一个发布版本而不是调试".然后,您的项目将尝试使用python27.lib而不是python27_d.lib进行链接.请参考如何:创建发布版本
  2. 您还可以下载Python源代码并使用VS2008进行构建(是的,Python 2.7是使用VS 2008进行构建的).同样,如果您的目标是x64,则至少需要VS2008 Professional版本.这将生成python27_d.lib.请参考 Python开发人员指南
  1. Create a release build instead of Debug. Your project would then try to link with python27.lib instead of python27_d.lib. Refer How to: Create a Release Build
  2. You can also download the Python source and build it with VS2008 (Yes, Python 2.7 is build with VS 2008). Again if you are targeting x64, you need at-least VS2008 Professional Version. This will generate python27_d.lib. Refer Python Developer’s Guide

这篇关于如何解决Boost.Python中的__imp___Py_NoneStruct错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆