Unable to get most basic numpy array creation from C++ working.

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 * *

On Fri, Jul 30, 2010 at 10:08 PM, rif <rif@google.com> wrote:
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:
You must call import_array() before using any of the NumPy APIs. -Kevin

On Fri, Jul 30, 2010 at 10:17 PM, Kevin Jacobs <jacobs@bioinformed.com> < bioinformed@gmail.com> wrote:
On Fri, Jul 30, 2010 at 10:08 PM, rif <rif@google.com> wrote:
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:
You must call import_array() before using any of the NumPy APIs.
-Kevin
Thank you! rif
participants (2)
-
Kevin Jacobs <jacobs@bioinformed.com>
-
rif