extension programing with c

Gabriel Genellina gagsl-py at yahoo.com.ar
Wed Dec 6 22:05:36 EST 2006


At Wednesday 6/12/2006 13:41, mahdieh saeed wrote:

>I want to define extention module that connect to berkeley db.

You know support for Berkeley DB comes with the standard library, 
don't you? Look at the bsddb module.

>---------------------------------------------------------------------------------------------------------------
>function for define extention module is like this:
>name=importBDB.c
>------------------------------------------------------------------------
>#include <Python.h>
>#include <db.h>
>CreateDatabase(char *);
>static PyObject
>*insert_data(PyObject *self,PyObject *args) {
>char *databasename;
>if (!PyArg_ParseTuple(args, "s", &databasename)) {
>return NULL;
>}
>CreateDatabase(databasename);
>Py_RETURN_NONE;
>}
>static PyMethodDef data_methods[] = {
>{ "data", (PyCFunction)insert_data, METH_VARARGS, NULL },
>{ NULL, NULL, 0, NULL }
>};
>PyMODINIT_FUNC initdata() {
>Py_InitModule3("data", data_methods, "My first extension module.");
>}
>----------------------------------------------------------------------------------------------------------

Given that code, the source should be called data.c (not an absolute 
requisite, but at least it's easier that way).

>my compiler is gcc and compiling it with this command:
>
>gcc -shared -I/usr/local/include/python2.4 
>-I/usr/local/BerkeleyDB.4.5/include   \ importBDB.c BDB.c \ 
>-L/usr/local/BerkeleyDB.4.5/lib -ldb-4.5 -o insert.so
>
>there is an error occurs like this:
>gcc:  importBDB.c: No such file or directory
>gcc:  -L/usr/local/BerkeleyDB.4.5/lib: No such file or directory
>I know problem for compiler please help me

What are those \ for? gcc is trying to compile something with a space 
in front of the name...
Remove them and try again.
Why insert.so?
Note that this has nothing to do with Python...


-- 
Gabriel Genellina
Softlab SRL 

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar



More information about the Python-list mailing list