Search code examples
pythonc++visual-studio-2012pycharmboost-python

Boost-Python C++ project builds, How to use the new library from Python?


I have a VS12 project and exposed some of the classes to Python using boost-python. After some linkage issues my project finally builds correctly and generates a MySDK.lib and MySDK.dll. I called the Boost Python module the same as the library i.e. BOOST_PYTHON_MODULE(MySDK). Are these .lib and .dll all I need to use MySDK from Python?

I'm using Pycharm Community but can't find a way to import the generated MySDK.lib and MySDK.dll as a Python library module.

Saddly there isn't much information of what to do after the Boost Python coding exercise.


Solution

  • I changed my VS12 project output file extension to .pyd (Right Click on Project -> Properties -> Linker -> General -> Output File -> changed to $(OutDir)$(TargetName).pyd) and now I can load the library in Python from the command line but still can't from Pycharm.

    After that, made the directory where the .pyd (along with .lib and .dll) is located under the Path variable. Then Pycharm is able to successfully load and run my custom boost-python library.

    UPDATE The pyd that Python understands and can load is simply the dll renamed to pyd. Therefore, an even cleaner way is to leave the VS12 project as is generating the original $(OutDir)$(TargetName)$(TargetExt) i.e. dll output and simply add a Post-Build Event that copies the dll into a pyd:

    (Right Click on Project -> Properties -> Configuration Properties -> Build Events -> Post-Build Event -> Command Line) and add copy $(OutDir)$(TargetName)$(TargetExt) $(OutDir)$(TargetName).pyd