I am currently trying to use Boost Python to export a class and then use it in the appropriate program.
#define BOOST_PYTHON_STATIC_LIB
#include <Resource\ZipResourceFile.hpp>
#include <Resource\ResourceCache.hpp>
#include <Windows.h>
#include <boost/python.hpp>
#include <iostream>
int add(int a, int b)
{
return a + b;
}
class Foo
{
public:
Foo(int n);
~Foo();
void f();
};
Foo::Foo(int n)
{
}
Foo::~Foo()
{
}
void Foo::f()
{
std::cout << "Foo!!!" << '\n';
}
BOOST_PYTHON_MODULE(PyBackend)
{
using namespace boost::python;
def("add", add);
class_<Foo>("Foo", init<int>())
.def("f", &Foo::f);
}
int main(int argc, char* argv[])
{
PyImport_AppendInittab("PyBackend", init_PyBackend);
Py_Initialize();
PyRun_SimpleString("import PyBackend");
PyRun_SimpleString("foo = PyBackend.Foo(1)");
Py_Finalize();
{
int n;
std::cin >> n;
}
return 0;
}
Anyway, I have no idea where I can find the init_PyBackend function, although this seems like a logical thing that I would call if I hadn't used Boost.Python.
The module itself is not in a separate DLL; it compiled everything at the same time. Anyway, who has any ideas on what I can do?
source
share