编译BerkeleyDB示例。

时间:2011-11-14 23:41:58

标签: berkeley-db

我正在尝试执行berkeleyDB示例。我使用make和make install安装了BDB。在examples / c目录中,我做一个gcc ex _ * .c,对于任何一个例子,以下是我得到的。我是以正确的方式来做这件事吗?

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’

1 个答案:

答案 0 :(得分:0)

这可能是一个链接错误。您需要指定libdb共享库,例如“-ldb”。如果Berkeley DB库是在系统范围内安装的,那么您可以假设共享库和头文件安装在默认路径中(/ usr / lib,/ usr / lib64,/ usr / include)。如果没有,那么您需要明确包含正确的路径。假设默认安装Berkeley DB,您可以尝试类似

的内容
gcc -ldb your_sample.c -o your_sample

此外,您的问题与此帖有关:berkeley DB: can't compile c++ codes

或者,进入构建文件夹(例如“build_unix”)并运行“make examples”来构建示例。