Thursday, December 11, 2014

How to create python extended libraries using Boost on Windows

    Of course you need Visual C++ to execute all of these steps, I recommend using Visual Studio Express Edition

    1. Download Boost library and create bjam using bootstrap.bat script file
    2. If you use older Boost (prior to version 1.57.0) you have to open user-config.jam on tools/build/v2/, and type following section
       
      using python : 3.4 : C:\\Python34 : C:\\Python34\\include : C:\\Python34\\libs;


      It will depend on the Python version you installed on your system.And again, if you use Boost library version 1.57.0 you don't have to edit the user-config.jam.
       
    3. Build boost library with python support ( --with-python)
    4. Open Up your Visual Studio IDE, create new dll project
    5. Copy the simple program that includes in python boost documentation
    6. Open property page of your project
    7. Change Target Extension  into .pyd
    8. Change Target Name match with your extension module
    9. Add include directory with python include directory and your new installed boost library
    10. Add the library directory with your python libs path and with your boost's libs path
    11. Add additional dependency with python34.lib , DO NOT use python3.lib, it might caused troubled when loading library during python execution
    12. Build and test the library
    13. If there is troubled while loading your pyd file, it might need some "dll,  track its 
      dependency using tools which you can download from http://dependencywalker.com/

    NOTE:
    Add this line in your source codes project  if you configure your project using static library
    #define BOOST_PYTHON_STATIC_LIB


    This is the boost python library build command
    $ bjam --build-dir=D:\\Boost\\BuildDir --build-type=complete --with-python link=static threading=multi stage

    No comments:

    Post a Comment