[Numpy-discussion] Unable to get most basic numpy array creation from C++ working.

rif rif at google.com
Fri Jul 30 22:08:22 EDT 2010


Hi numpy-discuss
.
I've distilled my problem down to a very simple program that segfaults.  I'm
sure I'm doing something silly, but hopefully someone can point me in the
right direction.  I create a program called numpy_test.cc:

---------------------
#include <Python.h>
#include "numpy/arrayobject.h"

int main(int argc, char **argv) {
  Py_Initialize();

  npy_intp length[1];
  length[0] = 10;
  PyObject* my_array = PyArray_SimpleNew(1, length, NPY_FLOAT);

  return 0;
}
---------------------

Standing in the directory above where I've done an in-place build of
numpy-1.3.0, I compile with:
g++ numpy_test.cc  -I/usr/include/python2.5
-I/tmp/numpy-1.3.0/numpy/core/include -lpython2.5*

*It compiles clean, but the resulting executable crashes in the
PyArray_SimpleNew line [verified via debugger].  I have yet to get a call to
PyArray_SimpleNew to not segfault.

Any thoughts or advice are appreciated.

Cheers,

rif
*
*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20100730/75bb96f5/attachment.html>


More information about the NumPy-Discussion mailing list