Search code examples
berkeley-db

Compiling BerkeleyDB examples.


I am trying to execute the berkeleyDB examples. I installed BDB with a make and make install. In the examples/c directory, I do a gcc ex_*.c, for any example, and the following is what I get. Am I going about this the right way?

ex_access.c: In function ‘main’:
ex_access.c:34: error: ‘DBC’ undeclared (first use in this function)
ex_access.c:34: error: (Each undeclared identifier is reported only once
ex_access.c:34: error: for each function it appears in.)
ex_access.c:34: error: ‘dbcp’ undeclared (first use in this function)
ex_access.c:64: warning: format ‘%s’ expects type ‘char *’, but argument 4 has type ‘int’
ex_access.c:67: error: ‘DB’ has no member named ‘set_errfile’
ex_access.c:68: error: ‘DB’ has no member named ‘set_errpfx’
ex_access.c:69: error: ‘DB’ has no member named ‘set_pagesize’
ex_access.c:70: error: ‘DB’ has no member named ‘err’
ex_access.c:73: error: ‘DB’ has no member named ‘set_cachesize’
ex_access.c:74: error: ‘DB’ has no member named ‘err’
ex_access.c:77: error: ‘DB’ has no member named ‘open’
ex_access.c:78: error: ‘DB_CREATE’ undeclared (first use in this function)
ex_access.c:79: error: ‘DB’ has no member named ‘err’
ex_access.c:107: error: ‘DB_NOOVERWRITE’ undeclared (first use in this function)
ex_access.c:107: warning: passing argument 4 of ‘dbp->put’ makes integer from pointer without a cast
ex_access.c:107: error: too many arguments to function ‘dbp->put’
ex_access.c:111: error: ‘DB’ has no member named ‘err’
ex_access.c:112: error: ‘DB_KEYEXIST’ undeclared (first use in this function)
ex_access.c:120: error: ‘DB’ has no member named ‘cursor’
ex_access.c:121: error: ‘DB’ has no member named ‘err’
ex_access.c:130: error: ‘DB_NEXT’ undeclared (first use in this function)
ex_access.c:134: error: ‘DB_NOTFOUND’ undeclared (first use in this function)
ex_access.c:135: error: ‘DB’ has no member named ‘err’
ex_access.c:141: error: ‘DB’ has no member named ‘err’
ex_access.c:144: error: too many arguments to function ‘dbp->close’
ex_access.c:146: warning: format ‘%s’ expects type ‘char *’, but argument 4 has type ‘int’
ex_access.c:152: error: too many arguments to function ‘dbp->close’

Solution

  • this is probably a linking error. You'll need to specify the libdb shared library, eg, "-ldb". If the Berkeley DB libraries are installed system-wide, then you can assume that shared libraries and header files are installed in the default paths (/usr/lib, /usr/lib64, /usr/include). If not, then you'll need to explicitly include the correct paths. Assuming default installation of Berkeley DB, you can try something like

    gcc -ldb your_sample.c -o your_sample
    

    Also, your question is related to this post: berkeley DB: can't compile c++ codes

    Alternatively, go inside the build folder (eg, "build_unix") and run "make examples" to build the examples.