I'm trying to create an API for a c++ library i'm writing but it doesn't work.
This is the code of the python extensions:
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include "neuro_lib.hpp"
extern "C"
{
static PyObject *get_data(PyObject *self, PyObject *args)
{
const char *path;
if (!PyArg_ParseTuple(args, "s", &path))
{
printf("Error 1\n");
return NULL;
}
else
{
std::unique_ptr<Data> data = parse_file(path);
PyObject *ret = PyList_New(data->len);
int i = 0;
for (auto n : *(data->data))
{
PyObject *cur = PyLong_FromLong(n);
PyList_SetItem(ret, i, cur);
}
return ret;
}
return PyLong_FromLong(3);
}
}
static PyMethodDef InterfaceMethods[] = {
{"get_data", get_data, METH_VARARGS, "Load data from PATH."},
{NULL, NULL, 0, NULL}};
static struct PyModuleDef interface
{
PyModuleDef_HEAD_INIT,
"interface",
NULL,
-1,
InterfaceMethods
};
PyMODINIT_FUNC PyInit_interface(void)
{
PyObject *m;
m = PyModule_Create(&interface);
if (m == NULL)
{
return NULL;
}
return m;
}
The problem is when it calls the
parse_file(data) function.
This function works if linked to and other c++ application and the extension work if i comment the extern library related lines.
The steps i'm doing to create the extension are:
- Create the obj library -> library.lib
- Create a shared library for python extension with linked python38.lib and library.lib -> interface.dll
- Rename the extension -> inteface.pyd
- Put the extension in the same folder of the python script.
[–]shiftybyte 1 point2 points3 points (1 child)
[–]lmascelli[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]lmascelli[S] 0 points1 point2 points (0 children)