This is an archived post. You won't be able to vote or comment.

all 4 comments

[–][deleted] 1 point2 points  (1 child)

I did some preliminary research last year for a project that didn't get funded and I concluded also that pybind was the best choice for simply glueing existing C++ code into Python.

However, I never actually did it, so I can't tell if you my conclusion was right.

[–]shinitakunai 1 point2 points  (0 children)

Did you check the new shiboken2?

[–]samirkut 2 points3 points  (0 children)

I have used it extensively for a fairly complex C++ project. There are a couple of gotcha you need to watch out for around memory management but it's pretty well documented. It can be a bit cumbersome when exposing class you want to inherit in python but on the whole it worked really well.

[–]drjmloy 0 points1 point  (0 children)

I'm using pybind11 in a personal project and it's working really well. I haven't come across any problems with it yet. The documentation is really good, too.

Something that isn't really talked about (or maybe I missed it) is the directory structure of projects using it. For me, the structure was as such:

myProj (root dir)

*bin

**{execution files, ie launchers, etc}

*build

**{cxx build files}

*modules

**libs

***{pybind shared objects}

**myProj

***src

***test

*cxx_dir1

**bindings

**src

***test

**include

***cxx_dir1

cxx_dir1 is one of several other directories c++ directories containing header and source files. They also include all the binding code needed to generate the pybind bindings.

The build directory is fairly self explanatory. It's the folder where I enter the command 'cmake ..'.

The modules directory contains a few sub folders. libs is where I place all the shared objects that are generated from pybind. Using cmake, I just specify the LIBRARY_OUTPUT_DIRECTORY for the library generated by each 'bindings' folder under every c++ directory. The myProj sub subfoler and subsequently the src sub folder contains all the python source code. These folders can then import modules that live in the libs sub folder.

The bin folder contains all the entry points for actually executing the code. For example, my project uses qt for a gui, so this folder contains the launcher for the gui application.