extension programing with c

mahdieh saeed maheh_saied at yahoo.com
Wed Dec 6 11:41:42 EST 2006


Hi
  I want to define extention module that connect to berkeley db.
  I define function for connection to berkeley db with c language in one file and define other function for create extention module that can import from python.
   function for connection to berkeley db is like this:
  name=BDB.c
  ---------------------------------------------
  #include <db.h>
void CreateDatabase(char *databasename){
DB *dbp ;
int ret;
DB_ENV *myEnv;
u_int32_t env_flags;
char *databasename;
ret = db_env_create(&myEnv, 0);
if (ret != 0) {
fprintf(stderr, "Error creating env handle: %s\n", db_strerror(ret));
return -1;
}
env_flags = DB_CREATE |DB_INIT_MPOOL;
if((ret = myEnv->open(myEnv,"env55", env_flags , 0))!=0){
fprintf(stderr, "Error open environment: %s\n", db_strerror(ret));
}
db_create(&dbp,myEnv,0);
dbp->open(dbp,NULL,"university",databasename,DB_BTREE,DB_CREATE,0);
}
---------------------------------------------------------------------------------------------------------------
  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.");
}
----------------------------------------------------------------------------------------------------------
  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
   
  regards
  saeed 

 __________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20061206/7d333210/attachment.html>


More information about the Python-list mailing list