How to get boost.python tutorial example to link with Python3?

一个人想着一个人 提交于 2019-12-05 12:13:16

So through trial and error I found a way that works.

I am not able to recompile a boost library from Python27 to Python34 but if I start from a clean area (i.e freshly 7zipped) and do the following it works (all in a Visual Studio 2010 command prompt):

  1. Make sure you have a user-config.jam file in your home directory with the following content:

    #  MSVC configuration
    using msvc : 10.0 ;
    # Python configuration:
    using python : 3.4 : C:\\Python34 : C:\\Python34\\include : C:\\Python34\\libs ;
    
  2. cd C:\Boost\boost_1_55_0

  3. bootstrap
  4. b2 toolset=msvc-10.0 --build-type=complete --with-python --libdir=C:\Boost\lib\i386 install
  5. cd C:\Boost\boost_1_55_0\libs\python\example\tutorial
  6. set 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 (i.e add Boost Lib to path)
  7. bjam
  8. Modify hello.py to att () around print:

    import hello_ext
    print(hello_ext.greet())
    
  9. python hello.py prints hello, world (Note that python here is python 3.4.1 my default install)

So what I still don't know how to solve is how to recompile boost and/or how to support two python version at the same time. Ideas and suggestions are welcomed but at the moment I only need Python3 so I will not investigate that.

Another thing to note is that the pre-compiled headers found online all seem to be 2.7 only. I hope these steps helps someone else!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!