Forum Stats

  • 3,840,134 Users
  • 2,262,571 Discussions


problem use c for API

528215 Member Posts: 67
edited Aug 16, 2006 3:08AM in Berkeley DB
i use berkeley db .my operating system is unix freebsd and c for api.
i use gcc compiler for compile program.
my program is like this

#include <db.h>
#include <stdio.h>
int main()
DB *dbp ;
u_int32_t flags;
int ret;
ret =db_create(&dbp, NULL,0);
//if (ret != 0) {
flags = DB_CREATE;
ret = dbp->open(dbp,NULL,"test.db", NULL,DB_BTREE,0,0);
if (ret != 0) {
printf("error occured");
but when i compile this program diplay this error:
undefined reference to `db_create'
please help me.
if i need to use other compiler or install other software for run c program please say me


  • 512799
    512799 Member Posts: 494
    You didn't list the gcc command you used to compile/link.

    This error - "undefined reference to 'db_create'" - means that you
    are not linking against the Berkeley DB library when you attempt
    to load the program. It also could mean you are linking against the wrong version
    of a library.

    Here is an example of command syntax that works for me on SUSE.

    gcc -Wall -I/usr/local/BerkeleyDB.4.4/include inmem2.c -L/usr/local/BerkeleyDB.4.4/lib -ldb-4.4 -o inmem2.o

    env LD_LIBRARY_PATH=/usr/local/BerkeleyDB.4.4/lib ./inmem2.o

    Of course, you should substitute in the name of your own program
    and the desired output name.

    Since these procedures are not completely standardized, please
    check your compiler and loader documentation for specific information
    as to how to reference a library on your system during the link
    phase. You may need to set a value for LD_LIBRARY_PATH or a
    similar environment variable.

    Ron Cohen
  • 528215
    528215 Member Posts: 67
    Hi Ron
    thanks for your advice.

    mahdieh saeed
This discussion has been closed.