0
// compile and link:
// - regular:
//     g++ -std=c++11 -fPIC  -I/usr/include/python3.10/ -I/usr/lib/python3/dist-packages/numpy/core/include/ -I.. ../sf.cpp -lpython3.10
// - debug:
//     g++ -g -std=c++11 -fPIC  -I/usr/include/python3.10d/ -I/usr/lib/python3/dist-packages/numpy/core/include/ -I.. ../sf.cpp -lpython3.10d

#include <Python.h>
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#include <numpy/ndarrayobject.h>

int main()
{
    auto* dims = new npy_intp[2];
    dims[0] = 3;
    dims[1] = 4;

    PyObject* pyarray = PyArray_SimpleNew(2, dims, NPY_DOUBLE);
}

segfaults in PyArray_SimpleNew. gdb yields no clue. What's wrong?

Joachim W
  • 7,290
  • 5
  • 31
  • 59
  • Does this answer your question? [Numpy C-Api example gives a SegFault](https://stackoverflow.com/questions/7730717/numpy-c-api-example-gives-a-segfault) – Wombatz Jul 08 '22 at 08:39
  • Quite possible that `import_array();` will be part of the solution. However, just pasting this line into the above minimal example does not resolve the segfault. – Joachim W Jul 08 '22 at 09:04
  • Maybe this is a better duplicate: https://stackoverflow.com/questions/55887324/why-does-this-trivial-usage-of-pyarray-simplenewfromdata-segfault – Wombatz Jul 08 '22 at 10:10
  • Not clear where to insert `Py_Initialize()` and `import_array()`. I´d prefer to leave this question open unless my minimal failing example is resolved by a minimal working version. – Joachim W Jul 09 '22 at 12:46

0 Answers0