python - 坚持Boost-Python教程(Boost 1_64_0、Python3.6和msvc 14.0)

标签 python python-3.x boost boost-python bjam

我一直在尝试达到使用 Boost-Python 的 0 级(在安装了 VS2015 和 Python 3.6 的 Windows 10 上),即构建教程,基本上是过去整整 3 天的时间。 我首先尝试阅读官方教程:- http://www.boost.org/doc/libs/1_64_0/libs/python/doc/html/tutorial/tutorial/hello.html 但这行不通。在我看来,该示例的设置需要“tutorial”目录中的“Jamfile”和父目录中的“Jamroot”。

经过调查/搜索,我开始回答:- Can't run bjam to compile boost python tutorial 目前我陷入困境

fatal error C1083: Cannot open include file: 'boost/python/module.hpp': No such file or directory

我会继续尝试,但第一个问题:-

1) 在我看来,我应该能够使用 bjam.exe 以及 boost_1_64_0\libs\python\tutorial 中的以下文件进行构建:hello.cpphello.py、一些 .lib(例如 boost_python3-vc140-mt-gd-1_64.lib 等)、合适的 Jamfilebjam.exe 在教程目录中,在父目录中放置一个合适的 Jamroot ,在我的 HOMEPATH 中放置 user-config.jam 。是对的吗 ?

事实上,经过上周的深思熟虑和尝试,我更进一步,得到了以下链接器错误:-

LINK : fatal error LNK1207: incompatible PDB format in 'C:\Program Files\boost\boost_1_64_0\libs\python\example\tutorial\hello_ext.pdb'; delete and rebuild call "C:\Users\DIAMON~1\AppData\Local\Temp\b2_msvc_14.0_vcvarsall_x86.cmd" nul link /NOLOGO /INCREMENTAL:NO /DLL /NOENTRY /DEBUG /MACHINE:X86 /MANIFEST /subsystem:console /out:"hello_ext.dll" /IMPLIB:"hello_ext.pdb" /LIBPATH:"C:\Users\DiamondExp\AppData\Local\Programs\Python\Python36-32\libs" @"hello_ext.dll.rsp"

if %ERRORLEVEL% NEQ 0 EXIT %ERRORLEVEL%

...failed msvc.link.dll hello_ext.dll hello_ext.pdb hello_ext.pdb...

然后我失去了 - 我必须非常可耻地承认 - 当我愚蠢地删除了整个 boost 目录以从“干净状态”开始时,部分工作的 Jamfile/Jamroot 丢失了。真的很蠢。 无论如何,我真的找不到任何地方可以摆脱这个 fatal error LNK1207。

我非常渴望进入 Boost-Python 的领域,这会让我的生活变得更加轻松。因此,我非常感谢经验丰富的 Boost-Python 和/或 Boost.Build 用户提供的任何意见,并可能得到以下具体问题的答案:

2)我应该如何修改我的 'libs\python\example\Jamroot' (特别是在“”之后)和 'libs\python\example\tutorial\Jamfile' ? 当前状态转载如下。 Boost.Python 所谓的“默认位置”是什么?

3) 放弃 bjam.exe 并尝试直接使用 VisualStudio 2015 进行构建是否是一个很好的替代方案? 就像那里:Building/including Boost.Python in VS2013

4) 从一些帖子来看,Boost 1_55 之后发生了一些事情。有几个人无法让它发挥作用。 Boost-Python 和 msvc14.0 或 Python 3.x 之间有任何已知的兼容性问题吗? 例如 : Compile boost-python tutorial with VS-2015 CTP 5 and Python 3.5a on Windows 10 TP

5) 我对 32 位/64 位的事情感到困惑。我安装了 64 位操作系统 (Windows10) 和 Python 32 位。我应该将 b2.exe 调用中的“地址模型选项”与什么相匹配?这有什么关系吗?

6) 这里值得使用 .dll 而不是 .lib 吗?

希望有人能做到这一点......

Jamfile:(默认情况下没有任何修改)

import python ;

project tutorial
  : requirements
    <location>.
    ;

python-extension hello_ext : hello.cpp ;

run-test hello : hello_ext hello.py ;

alias test : hello ;
explicit test ;

果酱:

import python ;

if ! [ python.configured ]
{
  ECHO "warning: no Python configured in user-config.jam" ;
  ECHO "warning: will use default configuration" ;
  using python ;
}

# Adjust the following if Boost.Python isn't installed in a default location
lib boost_python ;

project
  : requirements
    <include>C:\\Users\\DiamondExp\\Downloads\\boost_1_64_0\\boost_1_64_0\\boost\\python
    <library>boost_python
;

rule run-test ( test-name : sources + )
{
  import testing ;
  testing.make-test run-pyd : $(sources) : : $(test-name) ;
}

#build-project quickstart ;
build-project tutorial ;
if [ python.numpy ]
{
  build-project numpy ;
}

用户配置.jam

# -------------------
# MSVC configuration.
# -------------------

# Configure specific msvc version (searched for in standard locations and PATH).
using msvc : 14.0 : "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\bin\\cl.exe" ;


# ---------------------
# Python configuration.
# ---------------------

# Configure specific Python version.
# using python : 3.6 : /usr/bin/python3 : /usr/include/python3.1 : /usr/lib ;

using python 
    : 3.6                   # Version
    : C:\\Users\\DiamondExp\\AppData\\Local\\Programs\\Python\\Python36-32\\python.exe      # Python Path
    : C:\\Users\\DiamondExp\\AppData\\Local\\Programs\\Python\\Python36-32\\include         # include path
    : C:\\Users\\DiamondExp\\AppData\\Local\\Programs\\Python\\Python36-32\\libs            # lib path(s)
    : <define>BOOST_ALL_NO_LIB=1
    ;

最佳答案

如果您对 C++ 到 Python 感兴趣,您应该看看 Pybind11 。它是一个基于 Boost 的纯头文件库,专注于将 C++ 绑定(bind)到 Python。

您可以下载所有资源here

当我意识到在 Windows 上设置 Boost python 库非常危险时,我选择了这个选项。

关于python - 坚持Boost-Python教程(Boost 1_64_0、Python3.6和msvc 14.0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45284693/

相关文章:

python - Tkinter:如何创建选择框

python - 根据 Pandas 数据框中的另一列设置列值

python-3.x - 如何在Python Selenium Appium中的textarea中 "send_keys"多行?

c++ - 如何重启 boost::timer::cpu_timer?

Python Spyder 重置

python - 如何使用 Python + Selenium 在警报中单击 "OK"按钮

python - 子目录结构破坏了 C++ 扩展构建

python - 从值中获取键(值位于列表中)

c++ - 应该使用插入排序还是构造堆来 boost 性能?

sockets - 在 boost 套接字上设置选项 SO_SETFIB