如何获得boost.python教程示例以与Python3链接? [英] How to get boost.python tutorial example to link with Python3?

查看:107
本文介绍了如何获得boost.python教程示例以与Python3链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将boost.pythonpython 3.2+(最好是3.4)和Visual Studio 2010一起使用.

I want to use boost.python with python 3.2+ (preferably 3.4) and Visual Studio 2010.

当我尝试针对任何Python3(我已经测试过3.0、3.2和3.4)制作libs\python\example\tutorial示例时,它没有链接(请参见下文).当我将它链接到2.7时,它可以工作.

When I try to make the libs\python\example\tutorial example against any Python3 (I have tested 3.0, 3.2 and 3.4) it doesn't link (see below). When I link it against 2.7 it works.

两次尝试之间唯一要做的更改是更新主目录中的user-config.jam.

The only change I make between attempts is updating user-config.jam in my home directory.

因此当user-config.jam为:

#  MSVC configuration
using msvc : 10.0 ;
# Python configuration:
using python : 2.7 : C:\\Python27 : C:\\Python27\\include : C:\\Python27\\libs ;

当我运行bjam时,我得到:

C:\Boost\boost_1_55_0\libs\python\example\tutorial>bjam
link.jam: No such file or directory
...patience...
...patience...
...found 1678 targets...
...updating 8 targets...
compile-c-c++ bin\msvc-10.0\debug\hello.obj
hello.cpp
msvc.link.dll bin\msvc-10.0\debug\hello_ext.pyd
   Creating library bin\msvc-10.0\debug\hello_ext.lib and object bin\msvc-10.0\debug\hello_ext.exp
   msvc.manifest.dll bin\msvc-10.0\debug\hello_ext.pyd
   common.copy boost_python-vc100-gd-1_55.dll
   ..\..\..\..\bin.v2\libs\python\build\msvc-10.0\debug\boost_python-vc100-gd-1_55.dll
           1 file(s) copied.
common.copy hello_ext.pyd
bin\msvc-10.0\debug\hello_ext.pyd
           1 file(s) copied.
capture-output bin\hello.test\msvc-10.0\debug\hello
           1 file(s) copied.
**passed** bin\hello.test\msvc-10.0\debug\hello.test
...updated 8 targets...

如果我将user-config.jam更改为:

#  MSVC configuration
using msvc : 10.0 ;
# Python configuration:
using python : 3.4 : C:\\Python34 : C:\\Python34\\include : C:\\Python34\\libs ;

然后依次转到bjam cleanbjam:

C:\Boost\boost_1_55_0\libs\python\example\tutorial>bjam
link.jam: No such file or directory
...patience...
...patience...
...found 1685 targets...
...updating 9 targets...
compile-c-c++ bin\msvc-10.0\debug\hello.obj
hello.cpp
msvc.link.dll bin\msvc-10.0\debug\hello_ext.pyd
   Creating library bin\msvc-10.0\debug\hello_ext.lib and object bin\msvc-10.0\debug\hello_ext.exp
   hello.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) struct _object * __cdecl boost::python::detail::init_module(struct PyModuleDef &,void (__cdecl*)(void))" (__imp_?init_module@detail@python@boost@@YAPAU_object@@AAUPyModuleDef@@P6AXXZ@Z) referenced in function _PyInit_hello_ext
   bin\msvc-10.0\debug\hello_ext.pyd : fatal error LNK1120: 1 unresolved externals

           call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86 >nul
link /NOLOGO /INCREMENTAL:NO /DLL /DEBUG /MACHINE:X86 /MANIFEST /subsystem:console /out:"bin\msvc-10.0\debug\hello_ext.pyd" /IMPLIB:"bin\msvc-10.0\debug\hello_ext.lib" /LIBPATH:"C:\Python34\libs"   @"bin\msvc-10.0\debug\hello_ext.pyd.rsp"
           if %ERRORLEVEL% NEQ 0 EXIT %ERRORLEVEL%

...failed msvc.link.dll bin\msvc-10.0\debug\hello_ext.pyd bin\msvc-10.0\debug\hello_ext.lib bin\msvc-10.0\debug\hello_ext.pdb bin\msvc-10.0\debug\hello_ext.pdb...
...removing bin\msvc-10.0\debug\hello_ext.lib
...removing bin\msvc-10.0\debug\hello_ext.pdb
common.copy boost_python-vc100-gd-1_55.dll
..\..\..\..\bin.v2\libs\python\build\msvc-10.0\debug\boost_python-vc100-gd-1_55.dll
           1 file(s) copied.
...skipped <p.>hello_ext.pyd for lack of <pbin\msvc-10.0\debug>hello_ext.pyd...
...failed updating 3 targets...
...skipped 1 target...
...updated 2 targets...

在网上查找,我找到了一些有关此错误的参考,但没有解决方案... 这是最好的链接:

Looking online I find a couple of references to this error but no solutions... Here is the best link:

http://lists.boost.org/boost-build/2011/06/25147.php

我已经看到很多人在谈论使用Python3和boost.python,所以我一定缺少一些东西... 我是否需要以某种方式专门为Python 3编译boost?

I have seen many people talking about using Python3 and boost.python so I must be missing something... Do I need to compile boost specifically for Python 3 somehow?

帮助?

/罗伯特

推荐答案

因此,通过反复试验,我找到了一种可行的方法.

So through trial and error I found a way that works.

我无法将增强库从Python27重新编译为Python34 ,但是如果我从干净的区域(即刚压缩的7压缩)开始并执行以下操作(均在Visual Studio 2010命令中进行)提示):

I am not able to recompile a boost library from Python27 to Python34 but if I start from a clean area (i.e freshly 7zipped) and do the following it works (all in a Visual Studio 2010 command prompt):

  1. 确保您的主目录中有一个包含以下内容的user-config.jam文件:

#  MSVC configuration
using msvc : 10.0 ;
# Python configuration:
using python : 3.4 : C:\\Python34 : C:\\Python34\\include : C:\\Python34\\libs ;

  • cd C:\Boost\boost_1_55_0

    在打印周围将hello.py修改为att ()

    Modify hello.py to att () around print:

    import hello_ext
    print(hello_ext.greet())
    

  • python hello.py打印hello, world(请注意,这里的python是python 3.4.1我的默认安装)

  • python hello.py prints hello, world (Note that python here is python 3.4.1 my default install)

    所以我仍然不知道如何解决是如何重新编译boost和/或如何同时支持两个python版本.欢迎提出想法和建议,但是目前我只需要Python3,所以我不会对此进行调查.

    So what I still don't know how to solve is how to recompile boost and/or how to support two python version at the same time. Ideas and suggestions are welcomed but at the moment I only need Python3 so I will not investigate that.

    要注意的另一件事是,在网上找到的预编译标头似乎都只有2.7.我希望这些步骤可以帮助其他人!

    Another thing to note is that the pre-compiled headers found online all seem to be 2.7 only. I hope these steps helps someone else!

    这篇关于如何获得boost.python教程示例以与Python3链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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