一、开发环境
飞凌OK6410
ubuntu-9.10
交叉编译器arm-linux-gcc 4.3.2
二、移植步骤
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
# 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
# { { 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; }; }
# 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; }; }
# 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
这个时候你所创建的目录下应该有Makefile、libtool等四个文件
修改 BCC = arm-linux-gcc -g -O2
为 BCC = gcc -g -O2
8、执行make和make install命令,如下:
# make
# make install
# make install
这时应该不会有错误了,可以在目录 /usr/local 下看到目录 lib bin include
#chmod 775 sqlite3
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]#
[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]#
//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 = %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;
}
#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 = %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;
}
c、在超级终端下测试
[rootL-ant]#./test_sqlite test.db
"select * from film"
number = 1
name = aaa
number = 2
name = bbb
[rootL-ant]#
number = 1
name = aaa
number = 2
name = bbb
[rootL-ant]#
参考文献:http://www.cnitblog.com/zouzheng/archive/2006/12/18/20731.html
原文链接:https://www.f2er.com/sqlite/202371.html