一、开发环境
飞凌OK6410
ubuntu-9.10
交叉编译器arm-linux-gcc 4.3.2
sqlite-3.3.6(http://home.51cto.com/apps/download/index.php?s=/Index/index/)
二、移植步骤
ubuntu下root用户登录
1、将sqlite-3.3.6拷贝到目录 /root 下
# cd
2、解压sqlite-3.3.6 并到该目录下建立任意目录如 build
#tar -zxvf sqlite-3.6.22.tar.gz
#cd sqlite-3.6.22
#mkdir build
3、修改sqlite-3.3.6下的 configure
# vi configure
或者
#gedit configure
注释掉下列这些代码
 #
if test
"$cross_compiling" =
"yes"; then


 # { { echo
"$as_me:$LINENO:: error: unable to find a compiler for building build tools" >&5


 #echo
"$as_me: error: unable to find a compiler for building build tools" >&2;}


 # { (exit 1); exit 1; }; }


 #fi
 #
else


 # test
"$cross_compiling" = yes &&


 # { { echo
"$as_me:$LINENO:: error: cannot check for file existence when cross compiling"


 >&5


 #echo
"$as_me: error: cannot check for file existence when cross compiling" >&2;}


 # { (exit 1); exit 1; }; }
 #
else


 # test
"$cross_compiling" = yes &&


 # { { echo
"$as_me:$LINENO:: error: cannot check for file existence when cross compiling"


 >&5


 #echo
"$as_me: error: cannot check for file existence when cross compiling" >&2;}


 # { (exit 1); exit 1; }; }
保存退出;
4、到刚才你所创建的目录下,创建Makefile文件
# cd build
#../sqlite/configure --disable-tcl --host=arm-linux(
注:这里可能会出现错误,只要把configure的路径改为绝对路径就可以了)
这个时候你所创建的目录下应该有Makefile、libtool等四个文件
5、修改刚刚生成的Makefile文件
修改 BCC = arm-linux-gcc -g -O2
为 BCC = gcc -g -O2
6、由于是移植到arm上,为了在应用程序中引用sqlite3中的API接口,我们需要创建静态库,所以再次需要修改Makefile
修改内容如下:
 找到
 sqlite3$(TEXE): $(TOP)/src/shell.c .libs/libsqlite3.la sqlite3.h

 修改为

 sqlite3$(TEXE): $(TOP)/src/shell.c .libs/libsqlite3.a sqlite3.h


 找到

 -o $@ $(TOP)/src/shell.c .libs/libsqlite3.la

 修改为

 -o $@ $(TOP)/src/shell.c .libs/libsqlite3.a
(
注意:这次编译不会生成sqlite的可执行文件,因为只是为了得到sqlite3.a静态库
,在build目录下找到隐藏目录.libs ,该目录下有sqlite3.a)
7、重复步骤6把修改的Makefile中的sqlite3.a再改为sqlite3.la
8、执行make和make install命令,如下:
# make
# make install
这时应该不会有错误了,可以在目录 /usr/local 下看到目录 lib bin include
9、修改sqlite3可执行文件的执行权限
#chmod 775 sqlite3
10、将lib目录下的libsqlite3.so、libsqlite3.so.0、 libsqlite3.so.0.8.6 下载到开发板的 lib目录下,将sqlite3下载到 bin 目录下;
11、测试数据库:
 a、新建数据库
 [rootL-ant]# sqlite3 test.db
 SQLite version 3.6.18
 Enter
".help"
for instructions
 Enter SQL statements terminated with a
";"
 sqlite> create table film (number,name);
 sqlite> insert into film values (1,'aaa');
 sqlite> insert into film values (2,'bbb');
 sqlite> select * from film;
 1|aaa
 2|bbb
 sqlite>.quit
 [rootL-ant]#
b、测试程序

//test_sqlite.c

 #include <stdlib.h>

 #include <stdio.h>

 #include <sqlite3.h>


static
int callback(
void *NotUsed,int argc,char **argv,char **azColName)

 {


int i;


for(i=0; i<argc;i++)

 {

 printf(
"%s = %sn",azColName[i],argv [i]);

 }

 printf(
"n");


return 0;

 }


int main(
int argc,char **argv)

 {

 sqlite3 *db;


char *zErrMsg = 0;


int rc;


if( argc!=3 )

 {

 fprintf(stderr,"Usage: %s DATABASE SQL-STATEMENTn",argv[0]);

 }

 rc = sqlite3_open(argv[1],&db);


if( rc )

 {

 fprintf(stderr,"Can't open database: %sn",sqlite3_errmsg(db));

 sqlite3_close(db);

 }

 rc = sqlite3_exec(db,argv[2],callback,&zErrMsg);


if( rc!=SQLITE_OK )

 {

 fprintf(stderr,"SQL error: %sn",zErrMsg);

 }

 sqlite3_close(db);


return 0;

 }
使用如下命令编译测试程序:
arm-linux-gcc test.c -L.libs -I /root/sqlite-3.3.6/build -lsqlite3 -static
解释-I 指向静态库sqlite3.a所在目录,-I指向sqlite3.h 所在目录
c、在超级终端下测试
 [rootL-ant]#./test_sqlite test.db
"select * from film"
 number = 1
 name = aaa

 number = 2
 name = bbb

 [rootL-ant]#
到目前为止所有测试和移植就完成了。如有问题,错误请留言。
参考文献:http://www.cnitblog.com/zouzheng/archive/2006/12/18/20731.html (编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|