BerkeleyDB安裝及配置

2021-04-28 04:46:31 字數 3229 閱讀 1205

安裝過程:

(環境: kubuntu 7.10)

從其oracle公司官網http://www.oracle.com/technology/software/products/berkeley-db/index.html獲得其安裝包,當前版本為4.6.21

#tar zxfv db-4.x.tgz

#cd db-4.x/build_unix

(僅用於unix平台安裝)

#../dist/configure

(主意:

1、如果以gcc和g++編譯的話,須執行#env cc=gcc ccc=g++ ../dist/configure,否則編譯時出現段錯誤

2、預設狀態,berkeleydb的lib和include將被安裝到/usr/local/berkeleydb/下,需要更改這個路徑的話,可以加上選項--prefix,例如:#../dist/configure --prefix=/opt/berkeleydb.)

#make

#make install

#vi /etc/ld.so.conf

(並將berkeleydb的lib路徑加到該檔案的最後一行,這樣才能找到並載入它的庫檔案.ld.so.conf是系統動態鏈結庫的配置檔案.此檔案內,存放著可被linux共享的動態鏈結庫所在目錄的名字(系統目錄/lib,/usr/lib除外),各個目錄名間以空白字元(空格,換行等)或冒號或逗號分隔.)

#ldconfig

(#make uninstall解除安裝)

編譯方法(原始檔為test.c):

#gcc test.c -ggdb -i/usr/local/berkeleydb.4.6/include/ -l/usr/local/berkeleydb.4.6/lib/ -ldb -lpthread -o test.out

unix系統參考指南:http://www.oracle.com/technology/documentation/berkeley-db/db/ref/build_unix/solaris.html

berkeleydb參考資料:http://www.oracle.com/technology/documentation/berkeley-db/db/ref/toc.html

可使用如下程式測試_______________

#include

#include

#include

#include

//only this head should include for use bdb.

#include

#define database "free.db"

#define dblocat "/home/free/code/cc++/new"

int main()

//........if the environment does not exist create it. initialize the in-memory cache.

env_flags = db_create | db_init_mpool;

//........open the environment.

ret = myenv->open(myenv,dblocat,env_flags,0);

if (ret != 0)

if ((ret = db_create(&dbp, myenv, 0)) != 0)

if ((ret = dbp->open(dbp, null, database, null, db_btree, db_create, 0664)) != 0)

memset(&key, 0, sizeof(key));

memset(&data, 0, sizeof(data)); key.data = "sport";

key.size = sizeof("sport");

data.data = "football";

data.size = sizeof("football");

/*//......put data

if ((ret = dbp->put(dbp, null, &key, &data, 0)) == 0)

else

*///........put data nooverwrite

if ((ret = dbp->put(dbp, null, &key, &data, db_nooverwrite)) == 0)

printf("db: %s: key stored./n", (char *)key.data);

else

dbp->err(dbp, ret, "db->put");

//.......get data

if ((ret = dbp->get(dbp, null, &key, &data, 0)) == 0)

printf("db: %s: key retrieved: data was %s./n", (char *)key.data, (char *)data.data);

else

dbp->err(dbp, ret, "db->get");

//......del data

if((ret = dbp->del(dbp, null, &key, 0)) == 0)

printf("db: %s: key was deleted./n", (char *)key.data);

else

dbp->err(dbp, ret, "db->del");

//.........close, only when the db successful closed,the data can real write to the disk.

//if ((t_ret = dbp->close(dbp, 0)) != 0 && ret == 0)

//ret = t_ret;

//exit(ret);

if (dbp != null)

dbp->close(dbp, 0);

//.........close evn

//........when you are done with an environment, you must close it.

//........before you close an environment, make sure you close any opened databases

if (myenv != null)

myenv->close(myenv, 0);

return 0;

}

BerkeleyDB安裝及配置

安裝過程 環境 kubuntu 7.10 從其oracle公司官網http www.oracle.com technology software products berkeley db index.html獲得其安裝包,當前版本為4.6.21 tar zxfv db 4.x.tgz cd db 4...

BerkeleyDB 的編譯和安裝

2.cd db build unix dist configure 特別注意,如果要使用其c 介面的話,請執行 dist configure enable cxx 否則不會生成libdb cxx.so.3.make 4 sudo make install 5.在你的makefile 中新增 berk...

windows Nginx 安裝及配置

到nginx for windows php 其次安裝nginx 預設安裝到c nginx 然後以cgi 模式安裝php 到c php 接下來就是nginx 配置 我的nginx 配置單 php配置http www.tonightdream.com archives 207.html php解壓置c...