2

I want to write a wrapper for C++ code. My ultimate goal is to access classes and their functions written in C++ using python but right now, I am just trying to write a simple wrapper for hello world program. So, I looked online and saw boost.python is able to perform such feat. Their tutorial though is not so clear. I am trying to follow it but I am getting lost. Also the tutorial is based on windows systems and i am using mac, so it is creating more confusion for me.
I installed boost and bjam through homebrew.

brew install boost --with-python
brew install bjam

the code i am trying to wrap.

#include <iostream>
char const* greet(){
    return "hello world!"
}

Can you help me how to proceed with this?

For now, I downloaded Jammrootscript as directed in tutorial and edited the use-project boostto the current location of boost(/usr/local/Cellar/boost)
then, when i try to run bjam from terminal, i get following error

Jamroot:17: in modules.load
*** argument error
* rule use-project ( id : where )
* called with: ( boost : /usr/local/Cellar/boost; project boost-python-    quickstart : requirements <library>/boost/python//boost_python     <implicit-dependency>/boost//headers : usage-    requirements <implicit-dependency>/boost//headers )
* extra argument project
/usr/local/share/boost-build/src/build/project.jam:1138:see definition of rule 'use-project' being called
/usr/local/share/boost-build/src/build/project.jam:311: in load-jamfile
/usr/local/share/boost-build/src/build/project.jam:64: in load
/usr/local/share/boost-build/src/build/project.jam:145: in project.find
/usr/local/share/boost-build/src/build-system.jam:535: in load
/usr/local/share/boost-build/src/kernel/modules.jam:289: in import
/usr/local/share/boost-build/src/kernel/bootstrap.jam:139: in boost-build
/usr/local/share/boost-build/boost-build.jam:8: in module scope
5
  • 1
    i never used boost but you can use something called ctypes. this link has a complete example. Good luck Commented Nov 2, 2015 at 15:04
  • @Saraiva hey thanks for pointing out ctypes but it seems ctypes is a lengthy process as I have quite elaborate classes to work with. I was hoping if i could figure out boost.python, I can do the warping easily. Commented Nov 2, 2015 at 15:18
  • i see. Anyway, tipically in a wrapper you only expose a well-defined interface. Thats how ctypes work and how (for instance) JNI works (i recently had to create a Java wrapper for a c++ code). No matter how complex the existing code is remember that a wrapper accesses the wrapped code through simple well-defined calls (thus the ctypes). Good luck with the boost, i'm sure you will make it work Commented Nov 2, 2015 at 15:25
  • check out this link it looks like it might help Commented Nov 2, 2015 at 15:33
  • Hey thanks for the links. but sadly the boost.python tutorial is still out of my head and not yet working. i am killing myself over it now -.- Commented Nov 3, 2015 at 12:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.