I am trying to wrap a c++ library using pybind11 so I can use it with Python 3.x.
I tried wrapping the code using swig, but I ran into an issue where SWIG would generate the cxx file, but would not read the headers I was referencing, so it was suggested that I use pybind11 because it's better than swig (this is opinion I know), but I am having trouble finding resources on how I can reference/build the project.
My environment is:
- Windows 10 x64
- Anacondas build 4.4.0 with Python 3.6
- Visual Studios 2015 Professional (c++ installed)
When I create my interface file for Swig, I can do something easy like:
```
%module filegdbapi
%{
#include "FileGDBAPI.h"
%}
%include "FileGDBAPI.h"
```
Then on the swig build, I can reference the -I
to the location of the .h files.
How do I do something like this in pybind11? Is it that simple?
The documentation for pybind11 always shows building wrappers when you have the .cpp files. Can I use pybind11 in a ways that I can build a wrapper with swig? If so, how do you setup the files?
Can someone point me to a project that just generates a python wrapper from existing c++ code?
Thank you
Despite serving the same purpose, SWIG and Pybind11 are different tools.
As the name implies, SWIG (Simplified Wrapper and Interface Generator) is a generator tool that create Python binding for existing C++ code, using definitions written in a special language.
Pybind11, on the other hand, is a header-only C++ library that wraps raw Python-C API (that is old-style C and has steep learning curve) and allows to write Python bindings in modern C++. But you write those binding yourself by hand, using whatever C++ entities (functions, classes, templates etc.) that
pybind11::
namespace provides.