FAQ
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½B.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.htm

Search Discussions

  • Gabriel Genellina at Dec 7, 2006 at 3:05 am

    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
  • Gabriel Genellina at Dec 7, 2006 at 7:39 am
    At Thursday 7/12/2006 03:24, mahdieh saeed wrote:

    thanks for your help .I compile these code with out "\" but when I
    import module name insert error occurs like this:

    ImportError: Shared object "libdb-4.5.so" not found
    ---------------------------------------------------------
    my python code is the following:
    Please keep posting on the list, many others may have more clues than I.

    Your python code looks OK; the problem is that library not found.
    ldd may help, but since this is not related to python, you should
    look for help in a more convenient place.

    Anyway, are you sure the standard module bsddb is not enough?


    --
    Gabriel Genellina
    Softlab SRL

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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedDec 6, '06 at 4:41p
activeDec 7, '06 at 7:39a
posts3
users2
websitepython.org

People

Translate

site design / logo © 2022 Grokbase