我想将boost.python与python 3.2+ (最好是3.4)和Visual 2010结合使用。
当我尝试针对任何libs\python\example\tutorial (我已经测试了3.0、3.2和3.4)创建Python3示例时,它没有链接(见下文)。当我把它和2.7联系起来时,它就起作用了。
我在尝试之间所做的唯一改变是更新主目录中的user-config.jam。
因此,当是时,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 clean和bjam,我得到:
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...在网上我发现了一些关于这个错误的参考,但是没有解决办法.以下是最好的链接:
http://lists.boost.org/boost-build/2011/06/25147.php
我见过很多人在谈论使用Python3和boost.python,所以我肯定遗漏了一些东西.我是否需要为Python 3专门编译boost呢?
帮助?
/Robert
发布于 2014-06-19 21:45:45
因此,经过反复试验,我找到了一种行之有效的方法。
我无法将boost库从Python27重新编译为Python34 ,但如果我从一个干净的区域(即刚压缩的7次压缩)开始,并执行以下操作(所有这些都在Visual 2010命令提示符中),则:
user-config.jam文件:使用msvc : 10.0的msvc配置;# Python配置:使用python : 3.4 :C:\python 34:C:\python 34\include: C:\Python34\libs;cd C:\Boost\boost_1_55_0bootstrapb2 toolset=msvc-10.0 --build-type=complete --with-python --libdir=C:\Boost\lib\i386 installcd C:\Boost\boost_1_55_0\libs\python\example\tutorialset lib=c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\LIB;c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\ATLMFC\LIB;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\lib;C:\Boost\lib\i386;C:\Python34\libs (即向路径添加Boost Lib )bjam(),打印如下:
导入hello_ext打印(hello_ext.greet())python hello.py打印hello, world (注意这里的python是python3.4.1我的默认安装)因此,我仍然不知道如何解决如何重新编译boost和/或如何同时支持两个python版本。想法和建议是受欢迎的,但目前我只需要Python3,所以我不会对此进行调查。
另外要注意的是,在网上找到的预编译头似乎都只有2.7。我希望这些步骤能帮到别人!
https://stackoverflow.com/questions/24314644
复制相似问题