标题: sqlite+ARM+uClinux移植
第一步:

代码
使用交叉编译工具是:arm-elf-gcc/arm-elf-ar/arm-elf-ranlib
分别用于编译ojbect文件和将object文件打成uClinux需要的静态libsqlite3.a包,arm-elf-ranlib什么作用还不清楚。

第二步:

代码:

       
 交叉编译sqlite3提供两种版本的Makefile, 一种是通过configure由系统自
动配置环境。选项-disable-tcl, -build=arm-linux等;另一种是由自己手动
配置,将样板Makefile.linux-gcc拷贝Makefile,然后做一些适合自己环
境的编辑。由系统自动配置的Makefile同时生成了动态库*.so和静态库*.a
而且分别为这两种包编译sqlite3可执行文件【分别位于.lib目录下和当前目录】

第三步:

代码:

修改第二种做法的Makefile:
BCC用于编译lemon,只有先编译成功lemon后,才能编译后面的src/*.c。由于lemon是需要在host机中运行,所以BCC我们不能改成交叉编译只能用gcc编译。TCC是用于交叉编译的编译选项,所以改动TCC选项:
TCC = arm-elf-gcc -O6 -Wl,-elf2flt  //-elf2flt用于uClinux的BFLT格式
AR = arm-elf-ar cr
RANLIB = arm-elf-ranlib
因为在uClinux不支持动态库【需要动态分配程序的地址空间】和动态加载动态库【使用dlopen/dlsys/dlclose】,所以注释:
#MKSHLIB = gcc -shared
#SO = so
#SHPREFIX = lib
以及加上一个宏定义【此宏定义用于sqlite的增强功能即动态的加载动态库,uClinux上不需要,所以需要定义该宏】
OPTS = -DNDEBUG=1
OPTS += -DHAVE_FDATASYNC=1
OPTS += -DSQLITE_OMIT_LOAD_EXTENSION=1
Gcc中条件编译只需加上-D后面跟宏定义即可。

第四步:

代码:

我们不需要TCL版本的sqlite所以去掉此功能,编辑main.mk
去掉LIBOBJ+=中的tclsqlite3.o

第五步:

代码:

       
上面成功后,用arm-elf-gdb【可以仿真ARM7和9系列】启动基于ARMoulator
的仿真环境

运行:

代码:

Welcome to
          ____ _  _
        /  __| ||_|               
    _  _| |  | | _ ____  _  _  _  _
  | | | | |  | || |  _ \| | | |\ \/ /
  | |_| | |__| || | | | | |_| |/    \
  |  ___\____|_||_|_| |_|\____|\_/\_/
  | |
  |_|

GDB/ARMulator support by <davidm@snapgear.com>
For further information check:
http://www.uclinux.org/

Execution Finished, Exiting

Sash command shell (version 1.1.1)

sqlite> create table Lineup (int channelid, char lineupname);
sqlite> insert into Lineup values (13, 'cctv-1');
sqlite> insert into Lineup values (14, 'cctv-2');
sqlite> select * from Lineup;
13|cctv-1
14|cctv-2
sqlite>
SQLite——一个实现结构化查询语言(Structured Query Language,SQL)数据库引擎的小型的库。SQLite 不需要进行任何配置即可使用,并且可以完整地嵌入到任何应用程序中,而数据库则包含在单个文件中。许多编程语言都可以调用 SQLite 以实现数据的持久化。SQLite 还包括一种用于管理 SQLite 数据库的、名为 sqlite3 的命令行实用工具。
要开始学习这部分内容,首先下载 SQLite(请参见参考资料)。选择最新的源代码包,并将其下载到您的计算机中。(在撰写本文时,SQLite 的最新版本是版本 3.3.17,于 2007 年4 月 25 日发布。)这个示例使用了
http://www.sqlite.org/sqlite-3.3.17.tar.gz 中存储的文件。
在您获得了该文件之后,请对其进行解压缩。.tar.gz 扩展反映了该存档文件是如何构造的。在这个示例中,它是一个压缩了的 tar 存档文件。后面的扩展 .gz,表示 gzip(压缩);前面的扩展 .tar,表示 tar(一种存档格式)。要提取该存档文件的内容,只需要对其进行反向处理即可,也就是首先解压缩,然后打开该存档文件:
$ gunzip sqlite-3.3.17.tar.gz
$ tar xvf sqlite-3.3.17.tar
这两个命令在一个名为 sqlite-3.3.17 的新目录中创建了原始源代码的一个副本。顺便说明一下,.tar.gz 文件格式是非常常见的(称为 tarball),并且您可以使用 tar 命令直接解压缩 tarball 文件:
$ tar xzvf sqlite-3.3.17.tar.gz
其中的源代码和 SQLite 补充文件经过了很好组织,并且模拟了大部分的软件项目分发源代码的方式:
* README 文件对该项目进行了描述,并且通常用于说明如何构建该软件。(README 文件还详细地介绍了使用条款,或者许可证、适用情况。许多项目的许可证代码都符合 GNU 公共许可版本 2 中的条款,即所谓的“copyleft”许可证。在许可证与您打算如何使用该软件之间可能存在一定的冲突,如果您对此有任何疑问,最好请教一下合适的法律顾问。)
* src 目录中包含了相关的代码。
* test 目录中包含了一组测试,以验证该软件的操作是否正确。在开始构建或者进行了任何修改之后,请运行这些测试,这样可以增加对该软件的信心。
* contrib 目录中包含核心 SQLite 开发团队所没有提供的附加软件。对于像 SQLite 这样的库,contrib 中可能包含一些常用语言(如 C、Perl、PHP 和 Python)的编程接口。它可能还包括图形用户界面(GUI)包装,以及更多的内容。
* 在其他文件中,Makefile.in、configure、configure.ac 和 aclocal.m4 用于生成在您的 UNIX 版本中编译 SQLite 软件的脚本和规则。如果这个软件足够简单,那么要编译其代码,可能只需要一条简单的编译命令即可。但是,因为存在如此之多的 UNIX 变种(Mac OS X、Solaris、Linux、IBM? AIX? 和 HP/UX 等等),所以必须对宿主计算机进行分析,以确定它的功能及其实现。例如,邮件阅读应用程序可能会尝试确定本地系统是如何存储邮箱的,并包含对该格式的支持。

sqlite-3.3.6编译安装与交叉编译全过程详细记录


下文介绍的内容都是基于 Linux RedHat 9.0 平台的。
一、PC机编译安装
请阅读在安装包里的 INSTALL 文件。或者使用PEAR installer with "pear install sqlite"。SQLite已经内置了,你不需要安装任何附加的软件(additional software)。
Windows users可以下载SQLite扩展DLL(php_sqlite.dl)。
这里简单介绍一下:
假设你得到的是源代码sqlite-3.3.6.tar.gz,这里将告诉你怎么编译它。
解压sqlite-3.3.6.tar.gz 到 /home目录下
For example:
 tar zxvf sqlite-3.3.6.tar.gz -C /home           
 cd /home
 mkdir sqlite-ix86-linux
 cd /home/sqlite-ix86-linux/
 ../sqlite-3.3.6/configure --prefix=/home/sqlite-ix86-linux/
编译并安装,然后生成帮助文档
make && make install  && make doc
如果出现下列错误
../sqlite-3.3.6/src/tclsqlite.c: In function `DbUpdateHandler':
../sqlite-3.3.6/src/tclsqlite.c:333: warning: passing arg 3 of `Tcl_ListObjAppendElement' makes pointer from integer without a cast
../sqlite-3.3.6/src/tclsqlite.c: In function `tclSqlFunc':
../sqlite-3.3.6/src/tclsqlite.c:419: warning: passing arg 1 of `Tcl_NewByteArrayObj' discards qualifiers from pointer target type
这个都是tcl相关的错误,可以先安装ActiveTcl以解决.假如你不需要tcl支持,那么这个错误可以这样避免:
 cd /home/sqlite-ix86-linux/
    ../sqlite-3.3.6/configure --disable-tcl  --prefix=/home/sqlite-ix86-linux/
编译并安装,然后生成帮助文档 
 make && make install  && make doc
不出意外,将不会出现错误,那么
库文件已经生成在 /home/sqlite-ix86-linux/lib 目录下
可执行文件sqlite3已经生成在 /home/sqlite-ix86-linux/bin 目录下
下面创建一个新的数据库文件名叫"zieckey.db" (当然你可以使用不同的名字) 来测试数据库.
直接输入:  /home/sqlite-ix86-linux/bin/sqlite3 test.db
如果出现下面字样表明编译安装已经成功了.
SQLite version 3.3.6
Enter ".help" for instructions
sqlite>

二、交叉编译sqlite.3.3.6.tar.gz库文件
tar zxvf sqlite-3.3.6.tar.gz -C /home     (这一步前面已经有了,为了完整性,这里还是写出来)
mkdir /home/sqlite-arm-linux
设置交叉编译环境
export PATH=/usr/local/arm-linux/bin:$PATH
cd /home/sqlite-arm-linux/
../sqlite-3.3.6/configure  --disable-tcl --prefix=/home/sqlite-arm-linux/ --host=arm-linux
这步出现错误而没有生成Makefile
configure: error: unable to find a compiler for building build tools
前面检查arm-linux-gcc都通过了,怎么还说没有找到编译器呢?花了点时间看configure的脚本,太复杂了,又结合configure.ac看了一下。原来是要设置config_TARGET_CC和config_BUILD_CC两个环境变量。config_TARGET_CC是交叉编译器,config_BUILD_CC是主机编译器。重来:
export config_BUILD_CC=gcc
 export config_TARGET_CC=arm-linux-gcc
 ../sqlite-3.3.6/configure  --disable-tcl --prefix=/home/sqlite-arm-linux/ --host=arm-linux
又出现如下错误
 checking for /usr/include/readline.h... configure: error: cannot check for file existence when cross compiling
说readline.h的错,找到readline.h在/usr/include/readline/readline.h目录,我想这样解决
 ln -s /usr/include/readline/readline.h /usr/include/readline.h
但还是不行
../sqlite-3.3.6/configure  --disable-tcl --prefix=/home/sqlite-arm-linux/ --host=arm-linux
还是出现如下同样的错误
 checking for /usr/include/readline.h... configure: error: cannot check for file existence when cross compiling
上面说是要检查交叉编译环境,我可以肯定我的交叉编译环境是正确的,
所以我决定欺骗configure,我是这样做的
 cd /home/sqlite-3.3.6
将该目录下的 configure 文件的部分内容修改下(这里是根据   test "$cross_compiling" = yes &&  找到的 ),
这样可以让configure不去检查你的交叉编译环境。
  20420行 { (exit 1); exit 1; }; }改为 { (echo 1); echo 1; }; }
  20446行 { (exit 1); exit 1; }; }改为 { (echo 1); echo 1; }; }
 在回去重新配置下:
cd /home/sqlite-arm-linux/
 ../sqlite-3.3.6/configure  --disable-tcl --prefix=/home/sqlite-arm-linux/ --host=arm-linux
中间打印信息出现如下错误信息,
checking for /usr/include/readline.h... configure: error: cannot check for file existence when cross compiling
但是还是生成了Makefile文件一个libtool脚本,这些将在make时用到. 
注意:
如果Makefile文件中有如下语句
BCC = arm-linux-gcc -g -O2
请将其改掉,改成:
BCC = gcc -g -O2
编译并安装
 make && make install 
这里如果不出意外,将不会出现错误,那么库文件已经生成在 /home/sqlite-ix86-linux/lib 目录下 好了,就到这里。


sqlite-3.3.17交叉编译说明
 1、在Redhat Linux9上用arm-linux-gcc编译成功sqlite-3.3.17静态库版本。
2、在Redhat Linux9上用arm-linux-gcc编译成功sqlite-3.3.17动态库版本。
3、在Redhat Linux9上用arm-linux-gcc编译成功基于sqlite3静态库的应用程序。
4、在Redhat Linux9上用arm-linux-gcc编译成功基于sqlite3动态库的应用程序。
//==================================================================
//Compile SQLite using the cross-compiler such as arm-linux-gcc

1. first, get sqlite-3.3.17.tar.gz from www.sqlite.org

2. unzip it
   #tar -zxvf sqlite-3.3.17.tar.gz
3. change into the sqlite-3.3.17 directory
   cd sqlite-3.3.17
4. make a new directory such as 'build' under sqlite-3.3.17 directory,
   mkdir sqlite-arm-linux
5. First,Please ensure the cross compiler arm-linux-gcc included in PATH,
   Use 'echo $PATH',you can look out the PATH,
   if no,Set the path:
   export PATH=/usr/local/arm/2.95.3/bin:$PATH
6. 3.3.17版本的configure和Makefile都不需改动
7.
change into the build directory you created
   cd sqlite-arm-linux
8. call the edited configure script from the sqlite directory by using the following option:
   ../configure --disable-tcl --host=arm-linux
9. After that configure should have created a Makefile and a libtool script in your build directory.
10. run 'make' command to create the sqlite3 execute file, after a successful compile

11. Now you should find a hiden “.libs” directory in your build directory containing sqlite shared object files,
   like libsqlite3.so or static libray files like libsqlite3.a .

12. use 'file sqlite3' to look the inf of sqlite3, run 'arm-linux-strip sqlite3' to decrease the execute file size.
13. upload the sqlite3 to target ARM9 board by any FTP client and make it executive:
14. on ARM9 board with terminal or telnet ,run
   chmod 775 sqlite3
15. and then run sqlite3 like this
   sqlite3 ex2

16. ,if you see the following messages:
   SQLite version 3.3.17
   Enter ".help" for instructions
   sqlite>


在ARM-Linux平台上移植SQLite
1、软硬件平台
本文中采用的硬件平台为Sitsang嵌入式评估板。Sitsang评估板的核心是PXA255嵌入式处理器。底层软件系统是以ARM-Linux内核为基础的。
要将SQLite3移植到Sitsang评估板上,除了要有底层操作系统的支持外,还必须要有相应的交叉编译工具链。由于Sitsang评估板采用的是ARM-Linux作为底层操作系统,因此需要首先安装ARM-Linux工具链。关于ARM-Linux工具链的安装可以参阅文献[4]。ARM-Linux工具链通常安装在/usr/local/arm-linux/bin/目录下,通常以arm-linux-开头。本文中将会涉及到的主要是arm-linux-gcc、arm-linux-ar、arm-linux-ranlib这样三个工具。
2、移植过程
首先从http://sqlite.org下载SQLite 3.4.2。本文中假设将sqlite-3.4.2.tar.gz下载到/home/liyan/sqlite目录下。然后,通过下列命令解压缩sqlite-3.4.2.tar.gz并将文件和目录从归档文件中抽取出来:
# tar zxvf sqlite-3.4.2.tar.gz
解压抽取完成之后将会在/home/liyan/sqlite目录下生成一个sqlite-3.4.2/子目录,在该目录中包含了编译所需要的所有源文件和配置脚本。SQLite3的所有源代码文件都位于sqlite-3.4.2/src/目录下。
和在PC环境下编译SQLite3不同,不能通过sqlite-3.4.2/目录下的configure脚本来生成Makefile文件。取而代之的是必须手动修改Makefile文件。在sqlite-3.4.2/目录下有一个Makefile范例文件Makefile.linux-gcc。首先通过下面的命令拷贝此文件并重命名为Makefile:
# cp Makefile.linux-gcc Makefile
接下来,用vim打开Makefile文件并手动修改Makefile文件的内容。首先找到Makefile文件中的下面这样一行:
TOP = ../sqlite 将其修改为:TOP = .
找到下面这样一行:TCC = gcc -O6 将其修改为:TCC = arm-linux-gcc -O6
找到下面这样一行:AR = ar cr 将其修改为:AR = arm-linux-ar cr
找到下面这样一行:RANLIB = ranlib将其修改为:RANLIB = arm-linux-ranlib
找到下面这样一行:MKSHLIB = gcc -shared 将其修改为:MKSHLIB = arm-linux-gcc -shared
注释掉下面这一行:TCL_FLAGS = -I/home/drh/tcltk/8.4linux
注释掉下面这一行:LIBTCL = /home/drh/tcltk/8.4linux/libtcl8.4g.a -lm -ldl
vi中的查找方法:在命令模式下输入“?”加要查找的字符串,再回车。输入“n”为查找下一处。
原则上,对Makefile的修改主要包括两个方面:首先是将编译器、归档工具等换成交叉工具链中的对应工具,比如,gcc换成arm-linux-gcc,ar换成ar-linux-ar,ranlib换成arm-linux-ranlib等等;其次是去掉与TCL相关的编译选项,因为默认情况下,将会编译SQLite3的Tcl语言绑定,但是在移植到ARM-Linux的时候并不需要,因此将两个与TCL有关的行注释掉。
接下来,还需要修改的一个的文件是main.mk,因为Makefile包含了这个文件。找到这个文件中的下面一行:select.o table.o tclsqlite.o tokenize.o trigger.o把它替换成:select.o table.o tokenize.o trigger.o
也就是把该行上的tclsqlite.o去掉。这样编译的时候将不会编译SQLite3的Tcl语言绑定。
自此,修改工作就完成了,接下来就可以开始编译SQLite3了,这通过make命令即可完成:
# make
编译完成之后,将在sqlite3.4.2/目录下生成库函数文件libsqlite3.a和头文件sqlite3.h,这就是所需要的两个文件了。
3、测试
这里以SQLite官方站点http://sqlite.org的quick start文档中的测试程序为例对移植到ARM-Linux上的SQLite3进行测试。该程序清单如下:

#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] ? argv[i] : "NULL");

  }

  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]);

    exit(1);

  }

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

  if( rc )

{

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

    sqlite3_close(db);

    exit(1);

  }

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

  if( rc!=SQLITE_OK )

{

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

    sqlite3_free(zErrMsg);

  }

  sqlite3_close(db);

  return 0;

}

将此源程序保存为test.c,然后,通过如下命令编译该程序:

# arm-linux-gcc -I /home/liyan/sqlite/sqlite-3.4.2 -L /home/liyan/sqlite/sqlite-3.4.2 -o test test.c -lsqlite3

注意:可能会出现以下错误

/home/liyan/sqlite/sqlite-3.4.2/libsqlite3.a(os_unix.o)(.text+0x3ec): In function `sqlite3UnixDlopen':

: undefined reference to `dlopen'

/home/liyan/sqlite/sqlite-3.4.2/libsqlite3.a(os_unix.o)(.text+0x3f4): In function `sqlite3UnixDlsym':

: undefined reference to `dlsym'

/home/liyan/sqlite/sqlite-3.4.2/libsqlite3.a(os_unix.o)(.text+0x3f8): In function `sqlite3UnixDlclose':

: undefined reference to `dlclose'

collect2: ld returned 1 exit status

解决方法:在编译命令后加 “-ldl”

# arm-linux-gcc -I /home/liyan/sqlite/sqlite-3.4.2 -L /home/liyan/sqlite/sqlite-3.4.2 -o test test.c -lsqlite3 -ldl

上述编译命令中:

-I /home/liyan/sqlite/sqlite-3.4.2指明了头文件sqlite3.h所在的目录;

-L /home/liyan/sqlite/sqlite-3.4.2指定了库函数文件libsqlite3.a所在的目录;

-o test指定编译生成的文件名为test,test.c是源程序文件;

-lsqlite3指明要链接静态库文件libsqlite3.a。

编译完成后,可以通过NFS将test下载到Sitsang评估板上,通过ls命令可以看到test的大小只有300K左右:

[root@ee301 sqlite]# ls -l test

-rwxr-xr-x 1 root root 359148 09-03 13:22 test

接下来就可以测试test程序了。test程序接受两个参数:第一个参数为数据库文件名,第二个参数为要执行的SQL语句。程序中与SQLite3的API相关的地方主要有四个:sqlite3_open(), sqlite3_exec(), sqlite3_close(), sqlite3_free()。关于SQLite3的API接口请参阅文献[1]。

下面是测试test程序的完整过程,(在板子上):

/var/tmp/ly # ./test xyz.db "create table tbl0(name varchar(10), number smallint);"

/var/tmp/ly # ./test xyz.db "insert into tbl0 values('cyc', 1);"

/var/tmp/ly # ./test xyz.db "insert into tbl0 values('dzy', 2);"

/var/tmp/ly # ./test xyz.db "select * from tbl0;"

name = cyc

number = 1

name = dzy

number = 2

解释一下上面所用的测试命令:

第一条命令在xyz.db这个数据库文件中创建了一个tbl0表,表中包含两个字段,字段name是一个变长字符串,字段number的类型为smallint;

第二条命令向数据库的tbl0表中插入了一条记录(‘cyc’,1);

第三条命令向数据库的tbl0表中插入了一条记录(‘dzy’,2);

第四条命令则是查询表tbl0中的所有内容,与预期的一样,这条命令打印除了数据库中的两条刚插入的记录。

由此可以得出结论,这几条命令确实都已经按照预期的目标工作了。

同时,在向数据库中插入上面所示的数据之后,可以看到数据库文件xyz.db大小已经发生了变化:

/var/tmp/ly # ls -l test

-rw-r--r-- 1 root root 2048 Sep 3 2007  xyz.db

此时数据库文件xyz.db的大小为2K。自此,SQLite3数据库在Sitsang评估板上移植完成。测试结果表明数据库能够正常工作。

参考文献

[1] The Definitive Guide to SQLite。[美]Michael Owens著。Apress,2006

[2] http://sqlite.org

[3] SQLite移植手记。Hily Jiang。www.sqlite.com.cn,2006年11月

[4] Sitsang/PXA255 Evaluation Platform Linux User’s Guide。Intel Ltd,Sep. 2003

*主要参考*[5] 在ARM-Linux平台上移植SQLite,


sqlite嵌入式数据库在arm-linux下的编译全攻略
sqlite嵌入式数据库在arm-linux下的编译全攻略 [原创] 2004-06-02
作者:余涛(yut616_at_sohu.com)

第一步 sqlite在arm-linux下的编译
1、 下载sqlite:请到http://www.sqlite.org/download.html,将下载的代码包解开,将生成sqlite目录,另外新建一个build目录,如sqlite-arm-linux,应该是和sqlite目录平行的同级目录。

2、 请先确定你的PATH中已经包含交叉编译工具arm-linux-gcc。可用“echo $PATH”命令查看。如我的是“/opt/toolchain/gcc 3.2/toolchain/bin/”

3、 为了在arm-linux下能正常运行sqlite,我们需要修改一处代码,否则在arm板上运行sqlite时会出现下面的东东:
===============================
在文件btree.c中抛出断言,
assert( sizeof(ptr)==sizeof(char*) );
===============================
此断言是为了保证btree(B树)有正确的变量大小,如“ptr”和“char*”。 在不同的体系结构的linux,如x86和arm,会有些差别。刚好让我们在arm-linux下遇到了:-)。那么我们可以做一定的修改。
请修改sqlite/src/sqliteInt.h,找到如下部分:
#ifndef INTPTR_TYPE
# if SQLITE_PTR_SZ==4
# define INTPTR_TYPE int
# else
# define INTPTR_TYPE long long
# endif
在上面的代码前加上一句:
#define SQLITE_PTR_SZ 4
这样后面的“typedef INTPTR_TYPE ptr;”就是定义的“int”类型,而不是“long long”。

4、 准备使用configure进行一些配置。请在sqlite目录下的configure中找到如下4处,并将他们注释掉,这样可以让configure不去检查你的交叉编译环境。在此提示一下:请你自己确定自己的“arm-linux-”系列命令在你的PATH环境变量中。如:你可以输入“arm-linux-”再按“TAB”键,看其是否自动完成命令行。
#if test "$cross_compiling" = "yes"; then
# { { echo "$as_me:12710: 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:13264: 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:13464: 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:13490: 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; }; }
注释掉后,就可以执行configure了。在sqlite-arm-linux目录下,输入如下命令:
../sqlite/configure --host=arm-linux
这样在你的build目录中就将生成Makefile和一个libtool脚本,这些将在make时用到。

5、 修改Makefile文件
请修改Makefile文件,将下面的这行
BCC = arm-linux-gcc -g -O2
改掉,改成:
BCC = gcc -g -O2

一般地,我们都是将sqlite放到arm-linux的硬件板子上运行,所以我们一般将其编译成静态链接的形式。如果是共享so库的话,比较麻烦。
所以继续修改Makefile,找到如下地方:
sqlite:
将有其后的“libsqlite.la”改成
“.libs/libsqlite.a”
大功告成,现在可以make了。
应该不会出错,生成sqlite,libsqlite.a,libsqlite.so。你可以使用命令:find -name "sqlite";find -name "*.a";find -name "*.so"查

看文件所在的目录。
此时生成的sqlite文件是还未strip过的,你可以使用命令“file sqlite”查看文件信息。用strip处理过后,将去掉其中的调试信息,执行文

件大小也将小很多。命令如下:
arm-linux-strip sqlite

第二步 在arm板上运行sqlite
将sqlite拷贝到你的arm板上,方法很多,你需要根据自己的情况来选择。如ftp,cmdftp,wget等。
我的方法是使用wget将sqlite下载到arm板的/tmp目录,此目录是可写的。命令如下:
busybox wget ftp://192.168.0.100/sqlite
上面的命令,你可以看到我的板子上是已经有busybox来支持wget命令了的。:-)
好,开始运行
chmod +wx sqlite
./sqlite test.sqlite
会出现
sqlite>
提示符号,打个“.help”来看看命令先:-)
sqlite>.help
好了。现在sqlite已经在arm-linux下跑了起来。如何,感觉不错吧,在arm板子上玩玩“select * from”语句蛮爽吧:-)

友情提示:
如果sqlite在处理数据库过程中出现“The database disk image is malformed”,如:你在delete from sometable时,可能遇到这个问题。
那么就是你的arm板上的空间不够(如在/tmp下),请删除掉一些文件。我遇到的情况是空间还剩1-2M都会出现这个提示。删除后空余4M,就正

常了(如delete from sometable)。我是开的8M的ramdisk做开发玩的:-)

谢谢阅读。
欢迎转载,但请写明出处。

Undefined reference to dlsym
1) I checked out the code to directory called sqlite
2) I modified the Makefile.in <http://makefile.in/> to allow loading
extensions. We have to comment the following line
#TCC += -DSQLITE_OMIT_LOAD_EXTENSION=1
3) Created a directory called build. Ran configure and make from there.
4) I get "undefined refernce to dlsym, dlopen, dlclose" error.

Apparently the problem is with SQLite failing to find dynamic linker
library. I added LDFLAGS to command line before running make
Like this: LDFLAGS=-ldl make. Still it fails.

Please tell me what is the error.


You'll end up with a Makefile (and several other files) in this directory. Edit this mmakefile and comment out the line:

TCC += -DSQLITE_OMIT_LOAD_EXTENSION=1

I found this to be necessary to avoid errors later when I compile the shell.c (the sqlite3 CLP).

You may also what to edit the line "TLIBS = " to read

TLIBS = -ldl

Now do the following to compile and install:

~/dev/build$ make

After the make you will have a directory full of object files and the sqlite CLP executable called sqlite3

~/dev/build$ sudo make install

New libraries will be installed as /usr/local/lib/libsqlite3.a and /usr/local/lib/libsqlite3.so.0.8.6 (The former being the static lib and the later the shared lib). The sqlite3 executable is also installed in /usr/local/bin/.

Now make the amalgamated sqlite source file:

~/dev/build$ make sqlite3.c

You end up with a very large source file sqlite3.c and the header sqlite3.h which are essentially what you need to embed sqlite in your applications. You also have individual source files under the ~/dev/build/tsrc/. You will also find shell.c here - this is the source used to build the CLP.

To build the CLP using shared library:

~/dev/build$ gcc -O2 -o sqlite3 tsrc/shell.c -ldl -lsqlite3

Note that -lpthread is not required since shell.c does not require it.

You'll end up with a 39k sqlite3 executable file.

To build the CLP with the sqlite embedded:

~/dev/build$ gcc -O2 -o sqlite3 tsrc/shell.c sqlite3.c -ldl -lpthread

I end up with and executable of just under 380k size. Note that -lpthread needs to be specified since sqlite3.c uses it (I think).

I'm not sure how the static library can be used. When I try

~/dev/build$ gcc -O2 -o sqlite3 tsrc/shell.c -ldl -lpthread -l:libsqlite3.a

I end up with an executable of 1.4MB in size. It still works but I think it's not right

When cross-compiling sqlite-3.4.0, I encounter this linkage error:

./.libs/libsqlite3.so: undefined reference to `dlclose'
./.libs/libsqlite3.so: undefined reference to `dlopen'
./.libs/libsqlite3.so: undefined reference to `dlsym'

The solution:
===========
I added in Makefile.in the "-ldl" at the end of the line.
----
sqlite3$(TEXE): $(TOP)/src/shell.c libsqlite3.la sqlite3.h
$(LTLINK) $(READLINE_FLAGS) $(LIBPTHREAD) \
-o $@ $(TOP)/src/shell.c libsqlite3.la \
$(LIBREADLINE) $(TLIBS) -ldl

My configure command is:
--------------------------------------
./configure
'--build=i686-linux' \
--host=powerpc-wrs-linux-gnu \
--prefix=/usr/local \
'--disable-tcl' \
'--disable-debug' \
'--with-gnu-ld' \
'--enable-threadsafe' \
'--enable-releasemode' \
--disable-static

sqlite 移植到arm-linux

不过他们用的sqlite版本相对都要老一些,有很多说明已经不太实用。以下引用yeshi的文章,来自http://blog.chinaunix.net/u/16292/showart_149594.html

首先在http://www.sqlite.org/download.html上下载sqlite-3.3.13.tar.gz
$ tar -zxvf sqlite-3.3.13.tar.gz ~/sqliteforuclinux/
$ cd sqliteforuclinux/sqlite-3.3.13
查看readme,内容为:
For example:
    tar xzf sqlite.tar.gz    ;#  Unpack the source tree into "sqlite"
    mkdir bld                ;#  Build will occur in a sibling directory
    cd bld                   ;#  Change to the build directory
    ../sqlite/configure      ;#  Run the configure script
    make                     ;#  Run the makefile.
    make install             ;#  (Optional) Install the build products
我们现在要做的是交叉编译,要是为本机编译,可以照做就可以了
$ mkdir bld
$ cd bld
export config_BUILD_CC=gcc
export config_TARGET_CC=arm-linux-gcc
修改bld/目录下的 configure 文件的部分内容
20420行 { (exit 1); exit 1; }; }改为 { (echo 1); echo 1; }; }
20446行 { (exit 1); exit 1; }; }改为 { (echo 1); echo 1; }; }
$ ../sqlite-3.3.13/configure --disable-tcl  --prefix=/home/yeshi/sqliteforuclinux/bld --host=arm-linux
将/bld/Makefile文件中如下语句
BCC = arm-linux-gcc -g -O2
改成:
BCC = gcc -g -O2 //红色字体的是上面贴子上的,我的不用改的,已经是BCC = gcc -g
(我的也已经不需要改)
$make
$make install
bld/lib 目录下,
库文件已经生成在为了减小执行文件大小可以用strip处理,去掉其中的调试信息。
arm-linux-strip libsqlit3.so.0

在这个过程中起先遇到了不认识编译器的问题,修改环境变量解决问题,而这个文章中没有提到的是link tag的问题,要修改一下makefile文件,把 --tag=arm-linux放到libtool字段的link段的后面,去掉$(TCC),或者在$(TCC)之前空一格然后添上--tag=CC


uclinux下的sqlite嵌入式数据库移植

我们在这里讨论的是比较流行的嵌入式开发组合ARM+uclinux,即目标开发板为三星S3C4510,完成sqlite在其uclinux上的移植。
 
文假设你已经具备正确编译uclinux的kernel的能力,即有能力完成make menuconfig;make dep;make lib_only;make user_only;make romfs;make image;make。而且还能将自己写的类似helloworld程序加到“用户自定义应用程序”中,即你能完成“uClinux-dist/Documentation/Adding-User-Apps-HOWTO”中所描述的“用户程序的订制”。
大多数需要移植sqlite到uclinux的开发者,应该已经具备上面的能力,而只是不清楚如何修改sqlite来完成其在uclinux下的编译。如果你还不能完成上面的要求,那么请先做一定的准备工作,因为本范例所涉及到的内容主要是跟sqlite在uclinux下的移植有关,其他的在这个过程中出现的问题,开发者需要自行处理。
本范例使用的uclinux是uClinux-dist-20030522.tar.gz,你可以从http://www.uclinux.org得到适合你的软件包。
交叉编译工具是arm-elf-tools-20030314.sh,你也可以在http://www.uclinux.org找到它。本范例使用的sqlite是sqlite-2.8.15.tar.gz,本文的方法也适合于2.8.x系列的sqlite;可能有部分内容不适用于3.0.x系列的sqlite,因为3.0.x中源代码有较大的变化。
1、    下载sqlite:你可以到http://www.sqlite.org/download.html,下载sqlite-2.8.15.tar.gz软件包;
2、    将下载的软件包解压缩到uClinux-dist/user目录下;命令:$tar zxvf sqlite-2.8.15.tar.gz -C uClinux-dist/user/
现在在uclinux的user目录下,你应该可以看到sqlite目录了。解压缩到这个user目录主要是要将sqlite编译成一个普通的用户应用程序。
3、    用户应用程序的有关设置:按uClinux-dist/Documentation/Adding-User-Apps-HOWTO文档中说提到的,来添加sqlite作为一个用户应用程序,将其做成一个shell,这样就类似于uclinux自己的ps命令。
编辑文件uClinux-dist/user/Makefile    uClinux-dist/config/Configure.help    uClinux-dist/config/config.in
我是在这些文件里查找“cpu”有关的项,然后在它的下面,加上自己的sqlite项,这个过程并不复杂。通过上面的修改后,你现在就可以运行uclinux的make menuconfig,选中“CustomizeVendor/User Settings”,再选中“Miscellaneous Applications”,可以看到它现在出现了一个新的“sqlite (NEW)”,这个就是我们刚添加进去的sqlite项。
在稍后的make romfs中,uclinux会将你的sqlite编译进来,做成romfs的一部分,因为你在uClinux-dist/user/Makefile中已经加上要编译sqlite项了。这样在移植后的uclinux的/bin中将会有sqlite命令可以让你来执行。
好,现在我们就要对sqlite进行修改,来做移植工作。
在下面的描述中,我们将对以下几个文件进行一定的添加、修改,从而来完成sqlite在uclinux下的编译:
sqlite/main.mk        修改
sqlite/Makefile 添加
sqlite/src/os.c        修改
sqlite/src/shell.c     修改
对这几个文件进行修改时,请自己做好这些文件的备份,比如你可以将它们拷贝一份,改名成文件名后面带.bak。这个很重要,可以避免你在修改的过程出现问题而无法还原。
一、修改sqlite/main.mk
1、TCCX
将TCCX = $(TCC) $(OPTS) $(THREADSAFE) $(USLEEP) -I. -I$(TOP)/src 修改为TCCX = $(TCC) $(OPTS) $(THREADSAFE) $(USLEEP) -I. -I$(TOP)/src $(CFLAGS)即加上$(CFLAGS)标记.
2、 LIBOBJ
找到 # Object files for the SQLite library.将其中的tclsqlite.o去掉。即去掉tcl有关的东西。如果没有tclsqlite.o,那么不用处理它。

3、 sqlite$(EXE)
找到类似sqlite$(EXE)的一句
sqlite$(EXE):  $(TOP)/src/shell.c libsqlite.a sqlite.h
       $(TCCX) $(READLINE_FLAGS) -o sqlite$(EXE) $(TOP)/src/shell.c \
              libsqlite.a $(LIBREADLINE) $(THREADLIB)
替换为
shell.o:    $(TOP)/src/shell.c sqlite.h
       $(TCCX) $(READLINE_FLAGS) -c $(TOP)/src/shell.c
 
sqlite$(EXE):  shell.o libsqlite.a
       $(TCC) $(LDFLAGS) -o $@ shell.o \
              libsqlite.a $(LIBREADLINE) $(THREADLIB) $(LDLIBS)
即在sqlite$(EXE)上一行加上shell.o,及在其后加上$(LDLIBS)标记。这个是对/src/shell.c的编译方法的修改。
4、romfs
install:     sqlite libsqlite.a sqlite.h
       mv sqlite /usr/bin
       mv libsqlite.a /usr/lib
       mv sqlite.h /usr/include
替换为
romfs:     sqlite
       $(ROMFSINST) /bin/sqlite
即去掉make install项,加上make romfs项。 这个很重要,这将在romfs的/bin目录下生成sqlite。
5、clean:
clean:     
       rm -f *.o sqlite libsqlite.a sqlite.h opcodes.*
       rm -f lemon lempar.c parse.* sqlite*.tar.gz
rm -f $(PUBLISH)
      rm -f *.da *.bb *.bbg gmon.out
      rm -rf tsrc
替换为
clean:     
       rm -f *.o sqlite libsqlite.a sqlite.h opcodes.* sqlite.gdb
      rm -f $(PUBLISH)
      rm -f *.da *.bb *.bbg gmon.out
      rm -rf tsrc
 
distclean: clean
       rm -f lemon lempar.c parse.* sqlite*.tar.gz
       rm -f config.h
即增加make distclean项。
 
二、在sqlite下增加Makefile文件
在sqlite目录下应该没有Makefile文件,而只是有一个sqlite/Makefile.linux-gcc文件。我们要移植sqlite到uclinux,那么就要自己写一个合适的Makefile。
内容如下:
===========Makefile内容开始===========
#!/usr/make
#
# Makefile for SQLITE
#
# This is a template makefile for SQLite.  Most people prefer to
# use the autoconf generated "configure" script to generate the
# makefile automatically.  But that does not work for everybody
# and in every situation.  If you are having problems with the
# "configure" script, you might want to try this makefile as an
# alternative.  Create a copy of this file, edit the parameters
# below and type "make".
#
 
#### The toplevel directory of the source tree.  This is the directory
#    that contains this "Makefile.in" and the "configure.in" script.
#
TOP = .
 
#### C Compiler and options for use in building executables that
#    will run on the platform that is doing the build.
#
BCC = gcc -g -O2
#BCC = /opt/ancic/bin/c89 -0
 
#### If the target operating system supports the "usleep()" system
#    call, then define the HAVE_USLEEP macro for all C modules.
#
#USLEEP =
USLEEP = -DHAVE_USLEEP=1
 
#### If you want the SQLite library to be safe for use within a
#    multi-threaded program, then define the following macro
#    appropriately:
#
#THREADSAFE = -DTHREADSAFE=1
THREADSAFE = -DTHREADSAFE=0
 
#### Specify any extra linker options needed to make the library
#    thread safe
#
#THREADLIB = -lpthread
THREADLIB =
 
#### Leave MEMORY_DEBUG undefined for maximum speed.  Use MEMORY_DEBUG=1
#    to check for memory leaks.  Use MEMORY_DEBUG=2 to print a log of all
#    malloc()s and free()s in order to track down memory leaks.
#   
#    SQLite uses some expensive assert() statements in the inner loop.
#    You can make the library go almost twice as fast if you compile
#    with -DNDEBUG=1
#
#OPTS = -DMEMORY_DEBUG=2
#OPTS = -DMEMORY_DEBUG=1
#OPTS = -DNDEBUG=1
OPTS = -DMEMORY_DEBUG=1
 
#### The suffix to add to executable files.  ".exe" for windows.
#    Nothing for unix.
#
#EXE = .exe
EXE =
 
#### C Compile and options for use in building executables that
#    will run on the target platform.  This is usually the same
#    as BCC, unless you are cross-compiling.
#
TCC = $(CROSS)gcc
FLTFLAGS += -s 12000
#TCC = gcc -g -O0 -Wall
#TCC = gcc -g -O0 -Wall -fprofile-arcs -ftest-coverage
#TCC = /opt/mingw/bin/i386-mingw32-gcc -O6
#TCC = /opt/ansic/bin/c89 -O +z -Wl,-a,archive
 
#### Tools used to build a static library.
#
AR = $(CROSS)ar cr
#AR = /opt/mingw/bin/i386-mingw32-ar cr
RANLIB = $(CROSS)ranlib
#RANLIB = /opt/mingw/bin/i386-mingw32-ranlib
 
#### Extra compiler options needed for programs that use the TCL library.
#
#TCL_FLAGS =
#TCL_FLAGS = -DSTATIC_BUILD=1
#TCL_FLAGS = -I/home/drh/tcltk/8.4linux
#TCL_FLAGS = -I/home/drh/tcltk/8.4win -DSTATIC_BUILD=1
#TCL_FLAGS = -I/home/drh/tcltk/8.3hpux
 
#### Linker options needed to link against the TCL library.
#
#LIBTCL = -ltcl -lm -ldl
#LIBTCL = /home/drh/tcltk/8.4linux/libtcl8.4g.a -lm -ldl
#LIBTCL = /home/drh/tcltk/8.4win/libtcl84s.a -lmsvcrt
#LIBTCL = /home/drh/tcltk/8.3hpux/libtcl8.3.a -ldld -lm -lc
 
#### Compiler options needed for programs that use the readline() library.
#
READLINE_FLAGS =
#READLINE_FLAGS = -DHAVE_READLINE=1 -I/usr/include/readline
 
#### Linker options needed by programs using readline() must link against.
#
#LIBREADLINE =
#LIBREADLINE = -static -lreadline -ltermcap
 
#### Should the database engine assume text is coded as UTF-8 or iso8859?
#
# ENCODING  = UTF8
ENCODING = ISO8859
 
# You should not have to change anything below this line
###############################################################################
include $(TOP)/main.mk
===========Makefile内容结束===========
注:
1、  在uclinux下的sqlite的Makefile将不去用到TCL相关的库。
2、  在uclinux下的sqlite的Makefile将不去用到readline()。
 
在sqlite/README中有关于Makefile的一段描述:
The configure script uses autoconf 2.50 and libtool.  If the configure script does not work out for you, there is a generic makefile named "Makefile.linux-gcc" in the top directory of the source tree that you can copy and edit to suite your needs.  Comments on the generic makefile show what changes are needed.
你可以用sqlite/Makefile.linux-gcc作为蓝本来修改适合你自己的Makefile。
你如果有兴趣的话,可以把上面的Makefile的内容和sqlite/Makefile.linux-gcc内容diff对比一下,看看uclinux下的sqlite编译有哪些不同的地方。
 
三、修改sqlite/src/os.c
如果你的sqlite包中包括os.c文件那么就对其进行修改,没有os.c文件可能是你的sqlite版本比较新,那么无须修改。
将所有你找到的
if( s!=0 )
用if( s!=0 && errno != ENOSYS )
替换。
 
四、修改sqlite/src/shell.c
1、struct previous_mode_data 结构定义项:
将  int colWidth[100];
用  int colWidth[20];
替换。
2、struct callback_data 结构定义项:
将 
int colWidth[100];
int actualWidth[100];
char outfile[FILENAME_MAX];
用 
int colWidth[20];
int actualWidth[20];
char *outfilep;
对应替换。
 
再在结构下面增加:
#ifndef FILENAME_MAX
#define FILENAME_MAX    4095
#endif
char outfilename[FILENAME_MAX]; /* Filename for *out */
struct callback_data
{
...
};
#ifndef FILENAME_MAX
#define FILENAME_MAX    4095
#endif
char outfilename[FILENAME_MAX]; /* Filename for *out */
 
3、函数do_meta_command(...)中:
找到类似这样的一句
sqlite_exec(p->db, "PRAGMA database_list; ", callback, &data, &zErrMsg);
在它的前面有一句
memcpy(&data, p, sizeof(data));
现在在memcpy下面增加一行
data.cnt = 0;
即将结构中cnt的值赋为0 ;
现在代码会被修改成类似:
open_db(p);
memcpy(&data, p, sizeof(data));
data.cnt = 0;
 
再继续
找到类似这样的一句
strcmp(azArg[1],"stdout")==0
在它的下面的括号中
将      strcpy(p->outfile,"stdout");
用      p->outfilep = "stdout";
来替换。 
再在它下面的5-6行处
将         strcpy(p->outfile,azArg[1]);
用         strcpy(outfilename,azArg[1]);
               p->outfilep = outfilename;
替换。 
再继续
找到类似这样的一句
fprintf(p->out,"%9.9s: %s\n","output",
将fprintf(p->out,"%9.9s: %s\n","output", strlen(p->outfile) ? p->outfile : "stdout");
用fprintf(p->out,"%9.9s: %s\n","output", p->outfilep && strlen(p->outfilep) ? p->outfilep : "stdout");
替换
完成修改
上面的所有的对sqlite的修改完成后,你就可以make dep;make lib_only;make user_only;make romfs;make image了。
如果你对sqlite的修改,在make user_only过程中出现错误的话,你可以忽略make dep;make lib_only命令,直接再次进行make user_only;make romfs;make image;就可以了,而不用重复make dep;make lib_only。
make image会帮你生成romfs文件系统。现在在uClinux-dist/images下面就有编译生成的romfs文件系统了。这个就是我们需要的包含有sqlite的romfs了。
在上面的过程中,你可以不用在“make image”后再去“make”生成kernel内核,因为你只需要生成romfs就可以了,它里面已经有sqlite了。
现在你就可以把你生成的含有sqlite应用程序的romfs下载到开发板上运行一下。
Welcome to
          ____ _  _
         /  __| ||_|                
    _   _| |  | | _ ____  _   _  _  _
   | | | | |  | || |  _ \| | | |\ \/ /
   | |_| | |__| || | | | | |_| |/    \
   |  ___\____|_||_|_| |_|\____|\_/\_/
   | |
   |_|
GDB/ARMulator support by <davidm@snapgear.com>
For further information check:
Command: /bin/ifconfig eth0 up 10.0.0.2
Execution Finished, Exiting
init: Booting to single user mode
Sash command shell (version 1.1.1)
/> cd bin
/bin> ls -l sqlite
-rwxr-xr-x  1 0        0          327072  Jan 01 00:00 sqlite
/bin >cd /tmp
/tmp>sqlite test.sqlite
sqlite> create table my(name varchar(80), num smallint);
sqlite> insert into my values('yutao', 100);
sqlite> insert into my values('uclinux', 99);
sqlite> select * from my;
yutao|100
uclinux|99
sqlite> .tables
my
sqlite> .schema
create table my(name varchar(80), num smallint);
sqlite> .q
/tmp>ls –l test.sqlite
你要保证你的/tmp是可写的目录

好,现在你的sqlite就已经在uclinux运行起来了


SQLite移植手记

前几天成功地把Berkeley DB移植到uClinux上,虽然可以正常工作了,但是文件还是太大了些。今天来试一个稍微小一点的,它叫SQLite。 SQLite实现了大部分SQL92标准的SQL语句,同时支持ACID。还有其它许多特性这里不做深究,因为这在嵌入式领域来说应该是够用了。

Hily Jiang
Email&Gtalk: hilyjiang at Gmail
Blog: http://hily.iyi.cn/

下载:
下载页面:http://www.sqlite.org/download.html
我使用的还是当前最新版本:sqlite-3.3.7.tar.gz
(写完的时候已经更新出3.3.8版本了,真快啊……)

安装:
时间不多,简单介绍安装过程:
解压sqlite到uclinux-dist/user/sqlite/

============ 对uClinux的修改 ============
1. 下载sqlite,解压到uclinux-dist/user/下
2. 编辑uclinux-dist/user/下的Makefile,增加:

dir_$(CONFIG_USER_SQLITE_SQLITE)            += sqlite
3. uclinux-dist/config/Configure.help中增加:
CONFIG_USER_SQLITE_SQLITE
SQLite Database.
4. uclinux-dist/config/config.in最后增加:
mainmenu_option next_comment
comment 'Database'
bool 'sqlite'			CONFIG_USER_SQLITE_SQLITE
endmenu

============ 对SQLite的修改 ============
1. uclinux-dist/user/sqlite/main.mk中:
TCCX修改为:
TCCX = $(TCC) $(OPTS) $(THREADSAFE) $(USLEEP) -I. -I$(TOP)/src $(CFLAGS)
LIBOBJ修改为(一些模块不需要,比如tcl):
LIBOBJ+= alter.o analyze.o attach.o auth.o btree.o build.o \
callback.o complete.o date.o delete.o \
expr.o func.o hash.o insert.o loadext.o \
main.o opcodes.o os.o os_unix.o \
pager.o parse.o pragma.o prepare.o printf.o random.o \
select.o table.o tokenize.o trigger.o \
update.o util.o vacuum.o \
vdbe.o vdbeapi.o vdbeaux.o vdbefifo.o vdbemem.o \
where.o utf.o legacy.o vtab.o
sqlite3$(EXE)规则部分修改为:
shell.o: $(TOP)/src/shell.c sqlite3.h
$(TCCX) $(READLINE_FLAGS) -c $(TOP)/src/shell.c
sqlite3$(EXE): shell.o libsqlite3.a
$(TCC) $(LDFLAGS) -o $@ shell.o \
libsqlite3.a $(LIBREADLINE) $(THREADLIB) $(LDLIBS)
去掉install,增加:
distclean: clean
rm -f config.h
2. 拷贝Makefile.linux-gcc为Makefile,修改如下:
TCC = $(CROSS)gcc
AR = $(CROSS)ar cr
RANLIB = $(CROSS)ranlib
#TCL_FLAGS = -I/home/drh/tcltk/8.4linux
#LIBTCL = /home/drh/tcltk/8.4linux/libtcl8.4g.a -lm -ldl

 

编译:
在make menuconfig的user application部分可以看到刚添加的Database -->菜单,进入并选择SQLite,保存退出后按原先的步骤重新编译内核即可。如果只需要sqlite的库,那么make user_only就可以了。
编译完成后会在user/sqlite目录下生成库libsqlite3.a。

测试一下:
编写一个测试程序sqlitetest.c,代码如下(来自官方quick start):

#include <stdio.h>
#include <sqlite3.h>
static int callback(void *NotUsed, int argc, char **argv, char **azColName){
int i;
for(i=0; i
然后为它写一个Makefile,大致如下:
UCLINUX_PATH = /home/uClinux-dist
SQLITE_PATH = $(UCLINUX_PATH)/user/sqlite
CROSS = arm-elf-
CPU_CFLAGS = -O3 -Wall -mapcs-32 -mtune=arm7tdmi -fno-builtin -msoft-float -Os  \
-D__uClinux__ -D__ARM_CPU__  \
-I$(UCLINUX_PATH)/lib/uClibc/include -I$(UCLINUX_PATH)/linux-2.4.x/include \
-I$(SQLITE_PATH) \
-D_DEBUG_
CPU_LDFLAGS = -nostartfiles -Wl, -elf2flt -L$(UCLINUX_PATH)/lib/uClibc/lib
CPU_ARFLAGS = r
CPU_LDLIBS = $(UCLINUX_PATH)/lib/uClibc/lib/crt0.o $(UCLINUX_PATH)/lib/uClibc/lib/crti.o \
$(UCLINUX_PATH)/lib/uClibc/lib/crtn.o -lc
MY_LDFLAGS = -L$(SQLITE_PATH)
MY_LDLIBS = -lsqlite3
CFLAGS = $(CPU_CFLAGS)
LDFLAGS = $(CPU_LDFLAGS) $(MY_LDFLAGS)
LDLIBS = $(CPU_LDLIBS) $(MY_LDLIBS)
TOPDIR = ./
CC = $(CROSS)gcc
EXEC = sqlitetest
CSRC = sqlitetest.c
OBJS = $(patsubst %.c,%.o, $(CSRC))
all: $(EXEC)
$(OBJS): %.o : %.c
$(CC) $(CFLAGS) -c $< -o $@
$(EXEC): $(OBJS)
$(CC) $(OBJS) $(LDFLAGS) $(LDLIBS) -o $@
clean:
-rm -f $(EXEC) *.elf *.gdb *.o
运行make编译测试程序,生成的程序大小约300KB:
linux:/home/work/sqlite # ll
总用量 688
drwxr-xr-x  2 root root    264 2006-10-09 11:25 .
drwxr-xr-x  4 root root    160 2006-10-09 11:21 ..
-rw-------  1 root root    982 2006-10-09 11:25 Makefile
-rwxr--r--  1 root root 315584 2006-10-09 11:25 sqlitetest
-rw-------  1 root root    788 2006-10-09 11:21 sqlitetest.c
-rwxr-xr-x  1 root root 396538 2006-10-09 11:25 sqlitetest.gdb
-rw-r--r--  1 root root   1600 2006-10-09 11:25 sqlitetest.o
接着将测试程序下载到目标板,测试运行结果如下:
# /home/sqlitetest /home/testdb.db "CREATE TABLE my_table(id int, name varchar(20))"
# /home/sqlitetest /home/testdb.db "INSERT INTO my_table values(1, 'jianglj')"
# /home/sqlitetest /home/testdb.db "INSERT INTO my_table values(2, 'Hily Jiang')"
# /home/sqlitetest /home/testdb.db "SELECT * FROM my_table"
id = 1
name = jianglj
id = 2
name = Hily Jiang
#
 
 
By default, the configure script generates a makefile that includes
the -DSQLITE_OMIT_LOAD_EXTENSION option. It's just too big of a
security hole to do otherwise.
Open the generated Makefile and remove the line that sets this
option. You will also have to link the shell, sqlite3, against
libdl (add the -ldl option to the TLIBS variable) if you want
to build it.
# The fdatasync library
TLIBS = -ldl