收集嵌入式数据库Sqlite移植资料

来源:互联网 发布:linux 进程退出日志 编辑:程序博客网 时间:2024/06/03 04:40

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