我正在尝试关注 this tutorial关于为 Windows 的 python 包装 C++ 代码。我安装了 python。下载了最新版本的 boost(1_55)。首先我运行 bootstrap.bat 来构建 bjam.exe。接下来,我配置了 boost_1_55_0\tools\build\v2\user-config .jam 使用 msvc10 编译器并添加了 python 安装路径。 现在,基于教程:
Now we are ready... Be sure to cd to libs/python/example/tutorial where the tutorial "hello.cpp" and the "Jamroot" is situated.
Finally:
bjam
尝试在该目录中运行 bjam 时出现:“bjam 未被识别为内部或外部命令”错误。我在这里错过了什么? user-config.jam 应该驻留在另一个位置吗?还是将 bjam 添加到系统路径?
更新:
好的。感谢@john,我必须将 bjam 添加到系统路径。但是现在,运行它,hello_ext.lib 是在 \boost_1_55_0\libs\python\example\tutorial\bin\msvc-11.0\中创建的debug 但不是 DLL。根据教程,我应该获取扩展的 DLL 文件。现在,我不确定 python 如何与扩展链接。但如果我假设它确实像 C++,那么它应该与 hello_ext 链接。 lib.But 如果运行:
python hello.py
其中包含从扩展中导入的方法,python 运行时崩溃。没有关于此工作流程的综合教程吗?Boost 文档对此一无所知。
最佳答案
这对我有用:
1.) 解压缩 boost_1_55_0.zip
2.) 准备使用 Boost 库二进制文件
转到 boost_1_55_0 根目录并打开命令提示符并键入以下命令:
Bootstrap
3.) 找到 user-config.jam:
在命令提示符中键入以下内容:
ECHO %HOMEDRIVE%%HOMEPATH%
4.) 如果 user-config.jam 在你的 homedrive 目录中,请按如下所示更改它:
注意:
.jam 语言将“空格”视为参数的分隔!
# -------------------
# MSVC configuration.
# -------------------
# Configure msvc (default version, searched for in standard locations and PATH).
# using msvc ;
# Configure specific msvc version (searched for in standard locations and PATH).
using msvc : 10.0 : C:\\app\\tools\\MSVisualStudio2010\\VC\\bin\\cl.exe ;
….
# ---------------------
# Python configuration.
# ---------------------
# Configure specific Python version.
# using python : 3.1 : /usr/bin/python3 : /usr/include/python3.1 : /usr/lib ;
using python
: 2.5 # Version
: C:\\app\\tools\\Python25\\python.exe # Python Path
: C:\\app\\tools\\Python25\\include # include path
: C:\\app\\tools\\Python25\\libs # lib path(s)
: <define>BOOST_ALL_NO_LIB=1
;
5.) 配置后构建库!!
转到 boost_1_55_0 根目录并打开命令提示符并键入以下命令:
.\b2
6.) 将 user-config.jam 复制到\boost_1_55_0\libs\python\example\tutorial 7.) 进一步到\boost_1_55_0\stage\lib\
将libboost_python-vc100-mt-gd-1_55.lib重命名为boost_python-vc100-mt-gd-1_55.lib并复制到
\boost_1_55_0\libs\python\example\tutorial
8.) 现在您应该在\boost_1_55_0\libs\python\example\tutorial 目录中拥有所有这些文件
hello.cpp
hello.py
user-config.jam
Jamroot
boost_python-vc100-mt-gd-1_55.lib
bjam.exe
9.) 在\boost_1_55_0\libs\python\example\tutorial 中打开命令提示符
然后键入以下命令:
bjam
10.) 构建成功后..
你应该在目录中有这个文件:
hello_ext.dll
将此文件重命名为:
hello_ext.pyd
关于c++ - 无法运行bjam编译boost python教程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20093331/