前端之家收集整理的这篇文章主要介绍了
sqlite3的交叉编译移植,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
一、开发环境
飞凌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/)
二、移植步骤
1、将
sqlite-3.3.6拷贝到目录 /root 下
# cd
2、解压
sqlite-3.3.6 并到该目录下建立任意目录如 build
#tar -zxvf
sqlite-3.6.22.tar.gz
#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等四个
文件
修改 BCC = arm-linux-gcc -g -O2
为 BCC = gcc -g -O2
6、由于是移植到arm上,为了在应用程序中引用
sqlite3中的API接口,我们需要创建静态库,所以再次需要
修改Makefile

找到

sqlite3$(TEXE): $(TOP)/src/shell.c .libs/lib
sqlite3.la
sqlite3.h


修改为


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



找到


-o $@ $(TOP)/src/shell.c .libs/lib
sqlite3.la \


修改为


-o $@ $(TOP)/src/shell.c .libs/lib
sqlite3.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
10、将lib目录下的lib
sqlite3.so、lib
sqlite3.so.0、 lib
sqlite3.so.0.8.6 下载到开发板的 lib目录下,将
sqlite3下载到 bin 目录下;

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 <st
dio.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 = %s\n",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-STATEMENT\n",argv[0]);


}


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


if( rc )


{


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


sqlite3_close(db);


}


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


if( rc!=
sqlITE_OK )


{


fprintf(stderr,
"sql error: %s\n",zErrMsg);


}


sqlite3_close(db);


return 0;


}
使用如下命令编译测试程序:
arm-linux-gcc test.c -L.libs -I /root/
sqlite-3.3.6/build -l
sqlite3 -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