嵌入式数据库Sqlite移植教程

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

将下面的这行

sqlite3$(TEXT):$(TOP)/src/shell.c libsqlite3.la sqlite3.h

改成

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

因为运行时都是将SQlite放到Arm-linux的硬件板子上运行,所以一般将其编译成静态链接的形式。
编译并安装
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

#include

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

{

int i;

for(i=0; 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.s undefined reference to `dlclose''''''''
./.libs/libsqlite3.s undefined reference to `dlopen''''''''
./.libs/libsqlite3.s 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

一、测试

1. 从 sqlite 网站http://sqlite.org/download.html上下载最新的 sqlite 源码sqlite-autoconf-3070500.tar.gz,目前最新版本为 3.7.5

2. 解压缩源码,进入源码文件夹mkdir _install,进行正确的配置 configure ,生成正确的Makefile

Configure 命令如下:

CC=/usr/local/arm-2007q1/bin/arm-none-linux-gnueabi-gcc CXX=/usr/local/arm-2007q1/bin/arm-none-linux-gnueabi-g++ ./configure --host=arm-linux --prefix=`pwd`/_install --disable-tcl

3. Make

4. Make install 将生成的内容拷贝到 ./configure –prefix 指定的目录中即 _install 文件夹中

5. 将编译得到的 sqlite3 拷贝到开发板文件系统/bin 目录下

将编译得到的 /lib 目录下的库文件拷贝到开发板文件系统/lib 目录下

让交叉编译器也支持sqlite3 的方法:

将编译得到的 /include 目录下的库文件拷贝到交叉编译器/include 目录下

将编译得到的 /lib 目录下的库文件拷贝到交叉编译器/lib 目录下

6. 在开发板中运行 sqlite3 如果出现以下提示说明sqlite 移植成功

SQLite version 3.7.5
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite

二、数据库测试;

1. 简单命令测试如下:

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

2. 交叉编译sqlite_test 应用程序测试 sqlite ,应用程序源码和Makefile 文件在压缩包sqlite_test.tar.bz2 中

测试命令:

./sqlite_test new.db "create table film (number,name)"

./sqlite_test test.db “insert into”

./sqlite_test test.db “select *from tablename;”

嵌入式数据库Sqlite移植教程-转相关推荐

  1. 【嵌入式实验】《嵌入式数据库 sqlite 移植及使用》

    嵌入式数据库 sqlite 移植及使用 一.实验目的 二.实验内容 三.预备知识 四.实验设备及工具(包括软件调试工具) 五.实验步骤 实验一:移植嵌入式数据库 sqlite 1~5:安装 sqlit ...

  2. 南京邮电大学嵌入式系统开发实验3:嵌入式数据库sqlite移植及使用

    实验3  嵌入式数据库sqlite移植及使用 一.实验目的 理解嵌入式软件移植的基本方法,掌握sqlite数据库软件移植的步骤,掌握sqlite开发的两种方式-命令模式和C代码开发模式的使用方法,并编 ...

  3. Linux网络编程小项目sqlite,嵌入式数据库sqlite

    *************************************** * 嵌入式数据库sqlite在LPC22XX上的应用 * ******************************* ...

  4. 嵌入式数据库SQLite的编译、安装和使用[ZT]

    嵌入式数据库SQLite的编译.安装和使用 下文介绍的内容都是基于 RedHat Linux 9.0 平台的. 引言:sqlite简介 sqlite是嵌入式SQL数据库引擎SQLite(SQLite ...

  5. android 内嵌 数据库,安卓开发之嵌入式数据库sqlite的操作方法

    安卓App开发经常会需要嵌入式数据库sqlite的辅助,它可以存放我们必要的应用数据,下面介绍下如何使用java连接读取sqlite中的数据. 本文中的代码经本人测试可用,可以参考. 代码如下: DB ...

  6. Sqlite 移动嵌入式数据库Sqlite的日常SQL操作语句汇总

    序言:     嵌入式数据库Sqlite的基本sql使用汇总,使用测试起来,与关系型数据库mysql在语法上有很多的相似之处,先准备测试数据: CREATE TABLE COMPANY(ID INT ...

  7. 嵌入式数据库SQLite与Java

    嵌入式数据库SQLite与Java SQLite作为一个开源的嵌入式数据库产品,具有系统开销小,检索效率高的特性,适用于手机.PDA.机顶盒设备等电器,并且作为嵌入式数据库在可下载的消费类应用程序中运 ...

  8. 嵌入式数据库-SQLite的基本使用

     本项目以orange pi zero 2为例,开发板运行Linux(ubuntu)系统 与传统数据库的区别(MySql) SQLite是一个无服务器的数据库,是自包含的.这也称为嵌入式数据库,这意味 ...

  9. Java与嵌入式数据库SQLite的结合

    为什么80%的码农都做不了架构师?>>>    最近研究了一下嵌入式数据库,并使用Java与一个叫做SQLite的轻量级数据库结合写了个小程序,这个过程中也获得了不少经验,下面来总结 ...

最新文章

  1. 漫话:敏捷Scrum研发技术与过程管理实践
  2. 《C语言编程初学者指南》一2.9 理解运算符优先级
  3. 雷林鹏分享:Lua 数据库访问
  4. 报告显示:2018年北京人工智能相关产业达1500亿元
  5. 算术运算符_四则与取模运算
  6. react 引入html文件_React起手式
  7. mysql 重启_windows下重启mysql的方法
  8. Win10系统电脑不会一键还原系统怎么解决
  9. HTML+CSS+JS实现 贪吃蛇游戏源码
  10. 【BZOJ1901】Dynamic Rankings,树状数组套主席树
  11. java 代码智能提示,如何在Eclipse中设置Java、JavaScript、HTML智能代码提示
  12. 【阿里图标库的使用】
  13. 56: Recv failure: Connection was reset和55错误解决办法
  14. 项目-2.EVP论文与代码解析(Audio-Driven Emotional Video Portraits)
  15. html插入图片向下,HTML基础8--插入图片及嵌入
  16. 认证的政府与媒体类订阅号可取得网页授权接口了
  17. 用Python可以解决的数学问题,探究代数、统计、几何、概率等
  18. 基于用户点击偏好和阅读满意度的个性化新闻推荐技术
  19. 详解小程序的蓝牙模块
  20. [科幻]一堂宇宙生物课

热门文章

  1. 安卓java自实现mp3播放器,Android MediaPlayer实现音乐播放器实例代码
  2. discuz mysql data_discuz调取数据库数据
  3. python如何识别中文_python如何识别图片中的文字
  4. python数据可视化是什么_python3数据可视化是什么?
  5. Android ScrollView用法实例汇总
  6. linux samba安装配置 总结
  7. 你知道大数据强大在哪里!!!你永远也不会猜到
  8. Hyper-V用差异磁盘克隆系统
  9. 监听短信增删以及短信会话增删
  10. nodejs模块hashmap