making py modules with C

Shaun Hogan shogan at iel.ie
Mon Mar 20 05:56:33 EST 2000




> im tryin to make a module called mod so that when you type:
> >>>from mod import *
> >>> work()
> in the python interpreter, it prints
> >>>"worked"
> but of course it isnt working for me, could you please tell me whats wrong
> with the code:
> it makes ok i get 2 errors :undefined referance to main and undefined
> referance to PyInitModule4????.
> i cp it to /opt/python/Python-1.5.2/Modules
> i do a make in /opt/python/Python-1.5.2
> in Setup.local i added "mod newmodule.o -ldl -lsocket"
> and it still says the module mod does not exist????
>
> /*newmodule.c*/
>
> #include "Python.h"
> #define DEBUG
>
> static PyObject * getsub(PyObject * self, PyObject * args);
>
> static PyMethodDef wahooMethods[]=
> {
>     {"work",getsub,METH_VARARGS},
>     {NULL.NULL}
> } ;
>
> void initmod()
> {
>     (void) PyInitModule ("mod", wahooMethods);
> }
>
> #ifdef NEEDMAIN
> int main (void)
> {
>     printf("worked\n");
> }
> #endif
>
> static PyObject * getsub(PyObject * self, PyObject * args);
> {
>     printf("worked\n");
> }
>
>






More information about the Python-list mailing list