1

我是 python 编程的新手,希望将一些 C++ dll 合并到 python 中。我发现 boost.python 是这个问题最常见的答案,并且一直在尝试使用 boost.python 包附带的一个简单的“hello world”应用程序来测试它。按照教程在http://www.boost.org/doc/libs/1_54_0/libs/python/doc/tutorial/doc/html/python/hello.html

我正在使用 Microsoft Visual Studio 10.0 运行 Windows 7。

我的 python 目录是'C:\Python27',Boost 是'C:\Boost\boost_1_54_0'

我已将 user-config.jam 文件设置using msvc : 10.0 ;using python : 2.7 : C:\\Python27 ;

当我调用 bjam 时,我得到以下信息。

...failed msvc.link.dll C:\Boost\boost_1_54_0\bin.v2\libs\python\build\msvc-10.0\debug\boost_python-vc100-gd-1_54.dll C:\Boost\boost_1_54_0\bin.v2\libs\python\build\msvc-10.0\debug\boost_python-vc100-gd-1_54.lib C:\Boost\boost_1_54_0\bin.v2\libs\python\build\msvc-10.0\debug\boost_python-vc100-gd-1_54.pdb...
...removing C:\Boost\boost_1_54_0\bin.v2\libs\python\build\msvc-10.0\debug\boost_python-vc100-gd-1_54.lib
...removing C:\Boost\boost_1_54_0\bin.v2\libs\python\build\msvc-10.0\debug\boost_python-vc100-gd-1_54.pdb
...skipped <pbin\msvc-10.0\debug>hello_ext.pyd for lack of <pC:\Boost\boost_1_54_0\bin.v2\libs\python\build\msvc-10.0\debug>boost_python-vc100-gd-1_54.lib...
...skipped <pbin\msvc-10.0\debug>hello_ext.lib for lack of <pC:\Boost\boost_1_54_0\bin.v2\libs\python\build\msvc-10.0\debug>boost_python-vc100-gd-1_54.lib...
...skipped <pbin\msvc-10.0\debug>hello_ext.pdb for lack of <pC:\Boost\boost_1_54_0\bin.v2\libs\python\build\msvc-10.0\debug>boost_python-vc100-gd-1_54.lib...
...skipped <p.>boost_python-vc100-gd-1_54.dll for lack of <pC:\Boost\boost_1_54_0\bin.v2\libs\python\build\msvc-10.0\debug>boost_python-vc100-gd-1_54.dll...
...skipped <p.>hello_ext.pyd for lack of <pbin\msvc-10.0\debug>hello_ext.pyd...
...skipped <pbin\hello.test\msvc-10.0\debug>hello for lack of <pbin\msvc-10.0\debug>hello_ext.pyd...
...failed updating 3 targets...
...skipped 7 targets...

所创建的只是一个 .obj 文件,位于:

C:\Boost\boost_1_54_0\libs\python\example\tutorial\bin\msvc-10.0\debug

从我的基本有限知识看来,所依赖的文件在编译之前就被删除了。我一直在努力寻找解决方案,但无济于事。感觉就像我错过了一些非常基本的东西。

谢谢你。

编辑:更新到 python 3.3 似乎让我更接近了。它不再从 bin.v2 中删除这两个文件,但它仍然没有编译 .dll 或 .pyb 文件。

PS C:\Boost\boost_1_54_0\libs\python\example\tutorial> .\bjam
...patience...
...patience...
...found 1681 targets...
...updating 7 targets...
msvc.link.dll bin\msvc-10.0\debug\hello_ext.pyd
LINK : fatal error LNK1104: cannot open file 'boost_python-vc100-mt-gd-1_54.lib'

    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:\Python33\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...
...skipped <p.>hello_ext.pyd for lack of <pbin\msvc-10.0\debug>hello_ext.pyd...
...failed updating 3 targets...
...skipped 1 target...
4

2 回答 2

2

已解决:首先我通过运行重新构建了 boost.python b2 toolset=msvc-10.0 --with-python --user-config=user-config.jam --build-type=complete stageC:\Boost\boost_1_54_0然后我将boost_python-vc100-mt-gd-1_54.lib文件复制到了教程文件夹中。不确定这是最好的解决方案,但它现在似乎正在工作。

于 2013-08-29T16:28:10.613 回答
0

我建议在你的配置文件中提及 python 安装路径:

using python : 2.7 : C:\Python27\;

您是否 cd 进入 jamroot 和 hello.cpp 所在的同一目录?

于 2013-08-28T20:06:59.810 回答