How to solve __imp___Py_NoneStruct Error in Boost.Python?

孤街醉人 提交于 2019-12-23 19:13:04

问题


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

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

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

  1. I download the prebuilt binary and install it at C:\local\boost_1_54\.

  2. I run 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. Add C:\local\boost_1_54\; C:\Python27\include; to C/C++->General->Additional Include Directories.

  2. 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.

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

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:

error LNK2001: unresolved external symbol __imp___Py_NoneStruct

error LNK1120: 1 unresolved externals

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

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?

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

EDIT:

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

error LNK1104: cannot open file 'python27_d.lib'

Anyone can help me?


回答1:


The following answer tries to solve the problem

error LNK1104: cannot open file 'python27_d.lib'

_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.

Debug/Release

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. 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



回答2:


include:

  #include <python.h>

Boost doesn't have python api included... You need to build boost with python27.lib



来源:https://stackoverflow.com/questions/18963712/how-to-solve-imp-py-nonestruct-error-in-boost-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!