more embedding into C woes: crt1.o compile error

Chris Fonnesbeck spam at fisher.forestry.uga.edu
Tue May 21 17:57:07 EDT 2002


When trying to compile the code at the bottom of this message, I get
the following error:

/usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crt1.o: In function
`_start':
/usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crt1.o(.text+0x18):
undefined reference to `main'

(A similar error results when using Debian with gcc 2.95).  Here is
the call:

gcc -o carray carray.c -I/usr/include/python2.2
-L/usr/lib/python2.2/config/ -lpython2.2 -lnsl -ldl -lreadline
-ltermcap -lpthread -lutil -lm

Here is the code:

#include <math.h>
#include <Python.h>
#include <Numeric/arrayobject.h>

static PyObject* matrix(PyObject *self, PyObject *args){
        double x,y;
        int size;
        int M,n,m;
        PyArrayObject *result;
        int dimensions[2];
        Py_complex *data;
        Py_complex p;
        if(!PyArg_ParseTuple(args,"idd",&M,&x,&y))
                return NULL;
        dimensions[0]=M;
        dimensions[1]=M;
        result = (PyArrayObject
*)PyArray_FromDims(2,dimensions,PyArray_CDOUBLE);
        data = (Py_complex*)result->data;
        for(n=0;n < M;n++){
                for(m=0; m<M; m++){
                        p.real=x;
                        p.imag=y;
                        data[n*M+m] = p;
                }
        }
        return PyArray_Return(result);
}

static PyMethodDef testcomplexMethods[] = {
        {"matrix",matrix,1},
        {NULL,NULL}
};

void inittestcomplex(){
        PyObject *m, *d;
        m = Py_InitModule("testcomplex", testcomplexMethods);
        import_array();
        d = PyModule_GetDict(m);
}

Any help most appreciated!

cjf



More information about the Python-list mailing list