Berkeley db 4520 移植到ARM.docx
- 文档编号:9652445
- 上传时间:2023-02-05
- 格式:DOCX
- 页数:11
- 大小:18.78KB
Berkeley db 4520 移植到ARM.docx
《Berkeley db 4520 移植到ARM.docx》由会员分享,可在线阅读,更多相关《Berkeley db 4520 移植到ARM.docx(11页珍藏版)》请在冰豆网上搜索。
Berkeleydb4520移植到ARM
首先去下一个berkeleydb,下面这个是官方网站:
我所下到的最新版本是4.5.20
首先解压缩:
tarzxvfdb-4.5.20.tar.tar
cddb-4.5.20
可以看到有个README文件,它让我们进docs/index.html查看具体的文档。
查看文档完毕,开始编译,由于berkeleydb是用autoconf和libtool编译工程的,所以编译相当方便。
对于一般的Linux/Unix而言,只要进入build_unix目录,命令如下:
cdbulid_unix
../dist/configure#configre的参数可以使用-h命令查看
make
makeinstall
生成的目标文件和库都将在目录bulid_unix下。
如果要重新编译:
makeclean
make
而我要用在的ARM9上(ARM7也一样,都是flat的文件格式,库文件也是),我所用的交叉编译工具是arm-linux-gcc,版本3.3.2.我首先在db-4.5.20下新建了一个build_arm_linux目录,然后编译,命令如下:
mkdirbuild_arm_linux
cdbuild_arm_linux
../dist/configureCC=arm-linux-gcc--host=arm
make
哈,是不是很简单。
且慢,ARM上没法直接install的。
以后怎么使用呢?
你看看build_arm_linux下面是不是有db.h和libdb-4.5.a(静态库),这就是我们所要的文件,你可以把db.h拷贝到目标系统中的/usr/include下面,或者自己添加环境变量,同理,libdb-4.5.a也可以放到/usr/lib下面,这样你就可以想系统库一样调用它。
因为我只用一个工程要使用它,所以我是直接跟我的工程一起编译的,假使跟工程文件放在一起。
使用的时候只要
#include"db.h"即可,编译的时候注意加编译选项-L.-ldb-4.5就可以将库静态编译进去。
uClinux上BerkeleyDBv4.5.20移植手记
BerkeleyDB是一个很棒的开源的嵌入式数据库,它主要运行在Unix/Linux上。
现在它已成为Oracle的一部分,叫作OracleBerkeleyDB。
下面主要介绍一下它在我最近玩的uClinux上的移植过程。
HilyJiang
Email&Gtalk:
hilyjiangatGmail
Blog:
下载页面:
我使用的是当前最新版的4.5.20(点击下载)。
linux:
/home/work/db#ll
总用量9078
drwxr-xr-x2rootroot802006-10-0812:
36.
drwxr-xr-x11rootroot11202006-10-0812:
33..
-r-xr-xr-x1rootusers92818942006-10-0812:
36db-4.5.20.tar.gz
(一)解压
linux:
/home/work/db#tar-zxfdb-4.5.20.tar.gz
linux:
/home/work/db#cddb-4.5.20/
linux:
/home/work/db/db-4.5.20#ls
.db_checkpointdb_upgradelibdb_javaREADME
..db_deadlockdb_verifyLICENSErep
btreedb_dumpdistlockrepmgr
build_unixdb_dump185docslogrpc_client
build_vxworksdb_hotbackupenvmod_db4rpc_server
build_windowsdbincexamples_cmpsequence
clibdbinc_autoexamples_cxxmutextcl
commondb_loadexamples_javaostest
cryptodbmfileopsos_vxworkstxn
cxxdb_printloghashos_windowsxa
dbdb_recoverhmacperl
db185dbreghsearchphp_db4
db_archivedb_statjavaqam
docs目录下有我们需要的文档,包括快速入门、各种语言的API手册等资料。
(二)配置和编译
建立一个脚本以方便配置。
由于unix/linux编译时的工作路径必须是build_unix,因此我们需要在build_unix目录下创建脚本。
我创建了一个名为myconfig的脚本,内容如下:
linux:
/home/work/db/db-4.5.20/build_unix#cat-nmyconfig
1#!
/bin/sh
2
3CC=arm-elf-gcc\
4CFLAGS="-Os-D__uClinux__-fno-builtin-I/home/uClinux-dist/linux-2.4.x/include-I/home/uClinux-dist/lib/uClibc/include-I/home/uClinux-dist/lib/uClibc/include/../"\
5LDFLAGS="-Wl,-elf2flt-Wl,-move-rodata-L/home/uClinux-dist/lib/uClibc/lib-L/home/uClinux-dist/lib/uClibc/lib/../-lc"\
6../dist/configure\
7--prefix=/home/work/db/Berkeley.DB\
8--build=i686-linux\
9--host=arm-elf-linux\
10--disable-cryptography\
11--disable-hash\
12--disable-queue\
13--disable-replication\
14--disable-statistics\
15--disable-verify\
16--disable-compat185\
17--disable-cxx\
18--disable-debug\
19--disable-debug_rop\
20--disable-debug_wop\
21--disable-diagnostic\
22--disable-dump185\
23--disable-java\
24--disable-mingw\
25--disable-o_direct\
26--disable-posixmutexes\
27--disable-pthread_api\
28--disable-rpc\
29--disable-smallbuild\
30--disable-tcl\
31--disable-test\
32--disable-uimutexes\
33--enable-umrw\
34--disable-shared\
35--enable-static\
36--enable-fast-install\
37--disable-libtool-lock\
38--disable-largefile
关于configure配置参数的含义,可以运行"../dist/configure--help"查看帮助,这里不再介绍。
要强调的一点是uClibc只能用静态编译,因此一定要选择--disable-shared。
接着执行./myconfig运行配置并编译安装函数库:
linux:
/home/work/db/db-4.5.20/build_unix#./myconfig>/dev/null
configure:
WARNING:
Inthefuture,Autoconfwillnotdetectcross-tools
whosenamedoesnotstartwiththehosttriplet.Ifyouthinkthis
configurationisusefultoyou,pleasewritetoautoconf@gnu.org.
cat:
/etc/ld.so.conf.d/*.conf:
Nosuchfileordirectory
linux:
/home/work/db/db-4.5.20/build_unix#make>/dev/null&&makeinstall>/dev/null
../dist/../hmac/sha1.c:
96:
warning:
`R0'redefined
/usr/local/lib/gcc-lib/arm-elf/2.95.3/../../../../arm-elf/include/sys/ucontext.h:
40:
warning:
thisisthelocationofthepreviousdefinition
../dist/../hmac/sha1.c:
97:
warning:
`R1'redefined
/usr/local/lib/gcc-lib/arm-elf/2.95.3/../../../../arm-elf/include/sys/ucontext.h:
42:
warning:
thisisthelocationofthepreviousdefinition
../dist/../hmac/sha1.c:
98:
warning:
`R2'redefined
/usr/local/lib/gcc-lib/arm-elf/2.95.3/../../../../arm-elf/include/sys/ucontext.h:
44:
warning:
thisisthelocationofthepreviousdefinition
../dist/../hmac/sha1.c:
99:
warning:
`R3'redefined
/usr/local/lib/gcc-lib/arm-elf/2.95.3/../../../../arm-elf/include/sys/ucontext.h:
46:
warning:
thisisthelocationofthepreviousdefinition
../dist/../hmac/sha1.c:
100:
warning:
`R4'redefined
/usr/local/lib/gcc-lib/arm-elf/2.95.3/../../../../arm-elf/include/sys/ucontext.h:
48:
warning:
thisisthelocationofthepreviousdefinition
warning:
.rodatasectioncontainsrelocations
warning:
.rodatasectioncontainsrelocations
warning:
.rodatasectioncontainsrelocations
warning:
.rodatasectioncontainsrelocations
warning:
.rodatasectioncontainsrelocations
warning:
.rodatasectioncontainsrelocations
warning:
.rodatasectioncontainsrelocations
warning:
.rodatasectioncontainsrelocations
warning:
.rodatasectioncontainsrelocations
warning:
.rodatasectioncontainsrelocations
warning:
.rodatasectioncontainsrelocations
strip:
/home/work/db/Berkeley.DB/bin/db_archive:
不可识别的文件格式
strip:
/home/work/db/Berkeley.DB/bin/db_checkpoint:
不可识别的文件格式
strip:
/home/work/db/Berkeley.DB/bin/db_deadlock:
不可识别的文件格式
strip:
/home/work/db/Berkeley.DB/bin/db_dump:
不可识别的文件格式
strip:
/home/work/db/Berkeley.DB/bin/db_hotbackup:
不可识别的文件格式
strip:
/home/work/db/Berkeley.DB/bin/db_load:
不可识别的文件格式
strip:
/home/work/db/Berkeley.DB/bin/db_printlog:
不可识别的文件格式
strip:
/home/work/db/Berkeley.DB/bin/db_recover:
不可识别的文件格式
strip:
/home/work/db/Berkeley.DB/bin/db_stat:
不可识别的文件格式
strip:
/home/work/db/Berkeley.DB/bin/db_upgrade:
不可识别的文件格式
strip:
/home/work/db/Berkeley.DB/bin/db_verify:
不可识别的文件格式
编译过程中会出现一些warning,不用理它们。
安装完后,会在指定的安装目录/home/work/db/Berkeley.DB下生成函数库:
linux:
/home/work/db/db-4.5.20/build_unix#cd/home/work/db/Berkeley.DB/
linux:
/home/work/db/Berkeley.DB#ls
...bindocsincludelib
linux:
/home/work/db/Berkeley.DB#lllib/
总用量1962
drwxr-xr-x2rootroot1042006-10-0812:
57.
drwxr-xr-x6rootroot1442006-10-0812:
57..
-rw-r--r--1rootroot10022662006-10-0812:
57libdb-4.5.a
-rw-r--r--1rootroot10022662006-10-0812:
57libdb.a
(三)数据库操作测试
创建一个测试程序如下:
linux:
/home/work/db/Berkeley.DB#cat-ntestdb.c
1#include
2#include
3#include
4
5#defineDESCRIPTION_SIZE20
6intmain()
7{
8DB*dbp;/*DBstructurehandle*/
9u_int32_tflags;/*databaseopenflags*/
10intret;/*functionreturnvalue*/
11char*description="Grocerybill.";
12char*description1[DESCRIPTION_SIZE+1];
13DBTkey,data;
14floatmoney;
15
16/*Initializethestructure.This
17*databaseisnotopenedinanenvironment,
18*sotheenvironmentpointerisNULL.*/
19ret=db_create(&dbp,NULL,0);
20if(ret!
=0){
21/*Errorhandlinggoeshere*/
22printf("Createfail!
\n");
23}
24
25/*Databaseopenflags*/
26flags=DB_CREATE;/*Ifthedatabasedoesnotexist,
27*createit.*/
28
29/*openthedatabase*/
30ret=dbp->open(dbp,/*DBstructurepointer*/
31NULL,/*Transactionpointer*/
32"/home/my_db.db",/*On-diskfilethatholdsthedatabase.*/
33NULL,/*Optionallogicaldatabasename*/
34DB_BTREE,/*Databaseaccessmethod*/
35flags,/*Openflags*/
360);/*Filemode(usingdefaults)*/
37if(ret!
=0){
38/*Errorhandlinggoeshere*/
39printf("Creatednewdatabase.\n");
40}
41
42money=122.45;
43
44/*ZeroouttheDBTsbeforeusingthem.*/
45memset(&key,0,sizeof(DBT));
46memset(&data,0,sizeof(DBT));
47
48key.data=&money;
49key.size=sizeof(float);
50
51data.data=description;
52data.size=strlen(description)+1;
53
54ret=dbp->put(dbp,NULL,&key,&data,DB_NOOVERWRITE);
55if(ret==DB_KEYEXIST){
56dbp->err(dbp,ret,
57"Putfailedbecausekey%falreadyexists",money);
58}
59
60memset(&data,0,sizeof(DBT));
61
62data.data=&description1;
63data.ulen=DESCRIPTION_SIZE+1;
64data.flags=DB_DBT_USERMEM;
65dbp->get(dbp,NULL,&key,&data,0);
66
67printf("data:
%s\n",(char*)data.data);
68
69/*Whenwe'redonewiththedatabase,closeit.*/
70if(dbp!
=NULL)
71dbp->close(dbp,0);
72
73return0;
74}
这个程序会在目标板上/home/目录下创建一个文件名为my_db.db的数据库,接着增加一条记录,然后从数据库中读取出新添加的这条记录,最后关闭数据库。
程序要烧写到目标板上,需要进行交叉编译:
linux:
/home/work/db/Berkeley.DB#arm-elf-gcc-O3-Wall-mapcs-32-mtune=arm7tdmi-fno-builtin-msoft-float-Os-D__uClinux__-D__ARM_CPU__-I/home/work/uClinux-dist/lib/uClibc/include-I/home/uClinux-dist/linux-2.4.x/include-I/home/work/db/Berkeley.DB/include-D_DEBUG_-ctestdb.c-otestdb.o
linux:
/home/work/db/Berkeley.DB#arm-elf-gcctestdb.o-nostartfiles-Wl,-elf2flt-L/home/uClinux-dist/lib/uClibc/lib-L/home/work/db/Berkeley.DB/lib/home/uClinux-dist/lib/uClibc/lib/crt0.o/home/uClinux-dist/lib/uClibc/lib/crti.o/home/uClinux-dist/lib/uClibc/lib/crtn.o-lc-ldb-otestdb
linux:
/home/work/db/Berkeley.DB#ll
总用量1217
drwxr-xr-x6rootroot2802006-10-0813:
22.
drwxr-xr-x4rootroot1442006-10-0812:
50..
drwxr-xr-x2rootroot3762006-10-0812:
57bin
drwxr-xr-x14rootroot3842006-10-0812:
57docs
drwxr-xr-x2rootroot962006-10-0812:
57include
drwxr-xr-x2rootroot1042006-10-0812:
57lib
-rwxr--r--1rootroot5844762006-10-0813:
22testdb
-rw-r--r--1rootroot21712006-10-0813:
22testdb.c
-rw-------1rootroot21632006-10-0813:
09testdb.c~
-rwxr-xr-x1rootroot6736832006-10-0813:
22testdb.gdb
-rw-r--r--1rootroot15402006-10-
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Berkeley db 4520 移植到ARM 移植 ARM