I have got some code written in c++ which i am trying to use in python without rewriting the complete code in python again and i am using Pybind11 to build a python module for that. I am trying to achieve this thing in Microsoft Visual Studio 2015 by following this tutorial here https://pybind11.readthedocs.io/en/stable/basics.html
I did following things in visual studio. 1) Downloaded Pybind11 from https://codeload.github.com/pybind/pybind11/zip/master
2) Unzipped the file
3) In visual studio a started a new empty C++ project.
4) Added my python interpreter include folder ( C:/python27/include) and Pybind11( C:/Pybind11/include) in VC++ directories > include directories
5) Added additional dependencies (C:\Python27\libs\python27.lib) in Linker>input>Additional dependencies
6) To use the output file in Python i need a .pyd file so i modified here Configuration Properties>General>Target extension : .pyd
7) Change project defaults > configuration type to Dynamic Library (.dll)
So i am able to build my project and generate the .pyd file but when importing this module i am getting following error: ImportError: dynamic module does not define init function (initProject11)
I searched for this error and got this link http://pybind11.readthedocs.io/en/stable/faq.html but i could not find my solution.
So i am looking for the solution for above problem. Thanks a lot in advance.
here is my CPP file code
#include <pybind11/pybind11.h>
int add(int i, int j) {
return i + j;
}
namespace py = pybind11;
PYBIND11_PLUGIN(example) {
py::module m("example", "pybind11 example plugin");
m.def("add", &add, "A function which adds two numbers");
return m.ptr();
}