Boost 1.59.0 编译支持Python3的链接库

官方编译的Boost中只带了Python2的链接库,Python3的链接库需要自己特别编译,官方编译版下载地址:http://sourceforge.net/projects/boost/files/boost-binaries

1. 将boost_1_59_0源代码解压到C:Boost159

2. 修改user-config.jam

# MSVC configuration
using msvc : 12.0 ;
# Python configuration:
using python : 3.5 : C:\Anaconda3 : C:\Anaconda3\include : C:\Anaconda3\libs ;

3. 打开Visual Studio 2013 command prompt,(如果需要32位的链接库,则VS控制台,Python必须为32位;否则全部为64位)

  1)  cd C:Boost159

  2)  bootstrap

      3)  b2 toolset=msvc-12.0 --build-type=complete --with-python --libdir=C:Boost159 --abbreviate-paths architecture=x86 address-model=32 install -j4

4. 将C:Boost159中生成的python3链接库复制到官方编译版的lib文件夹中。

5. 新建C++工程,复制C:Boost159libspythonexamplegetting_started2.cpp到工程中,链接上boost_python3-vc120-mt-1_59.lib,编译生成一个dll文件。

6. 将dll文件改成pobject.pyd文件,与boost_python3-vc120-mt-1_59.dll一起拷贝到当前Python工程文件夹,在py文件中直接"import pobject",就能调用C++的函数了。

Reference:

[1] http://stackoverflow.com/questions/24314644/how-to-get-boost-python-tutorial-example-to-link-with-python3

[2] http://choorucode.com/2014/06/06/how-to-build-boost-for-visual-studio-2013/

原文地址:https://www.cnblogs.com/kind064100611/p/4353561.html