第三部分、SQlite的交叉编译和移植
时间:2007-04-11 来源:yeguo
作者:yeshi
QQ:251059619
Blog:http://blog.chinaunix.net/u1/33990/
一、简单介绍
在用到数据库的嵌入式系统中,我们可以用开放源码的sqlite,下面我将介绍两种方法,一个是交叉编译,在主机上生成相应的库文件,这样在编译应用程序的时候,可以在PC上完成静态编译,这样的应用程序可以直接拿到romfs上在嵌入式环境下运行,第二个是把整个数据库移植到romfs,在uClinux下运行sqlite。
二、交叉编译工具的安装
在ftp://ftp.arm.linux.org.uk/pub/linux/arm/toolchain/cross-2.95.3.tar.bz2上下载cross-2.95.3.tar.bz2
#mkdir –p /usr/local/arm
#cd /usr/local/arm
#tar jxvf `/cross-2.95.3.tar.bz2 //直接解到压缩到这个目录下就完成了
这时候的gcc为 2.95.3/bin/arm-linux-gcc,而它的 include 为 2.95.3/arm-linux/include ,对应的 lib 为 2.95.3/arm-linux/lib,也就是说,如果此时有什么为交叉编译需要的库和头文件,就必须拷到这里面来。
三、sqlite的交叉编译
(本过程参照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
四、利用上面编译好的库来交叉编译个数据库测试程序
源代码如下:test.c
#include <stdio.h>
#include <sqlite3.h>
int main(int argc, char *argv[])
{
sqlite3 *db=NULL;
int rc;
rc = sqlite3_open("test.db", &db);
if( rc )
{
printf("cannot open test.db ");
sqlite3_close(db);
exit(1);
}
else
printf("opened test.db successfully!\n");
sqlite3_close(db);
return 0;
}
$ arm-elf-gcc -Wall -O2 -Wl, -elf2flt -o test test.c -lsqlite3 -L/home/yeshi/sqliteforuclinux/bld/lib -I/home/yeshi/sqliteforuclinux/bld/include -static
生成test文件,静态连接的。
小插曲:我开始的时候并不是用arm-elf-gcc,而是arm-linux-gcc,可是出现cannot find entry symbol lf2flt,原因是工具链有问题,需要打 elf2flt 的补丁才可以。我就不打了,直接用从www.uclinux.org上给的arm-elf-gcc:)
把test文件拷到romfs/bin,同时在该目录新建个test.db(测试用)
$ genromfs -v -V "ROMdisk" -f ./images/romfs.img -d /usr/local/src/uclinux-s3cev40/romfs
$......../skyeye_1_2_2_Rel/binary/skyeye -e linux-2.4.x/linux
Welcome to
____ _ _
/ __| ||_|
_ _| | | | _ ____ _ _ _ _
| | | | | | || | _ \| | | |\ \/ /
| |_| | |__| || | | | | |_| |/ \
| ___\____|_||_|_| |_|\____|\_/\_/
| |
|_|
GDB/ARMulator support by <[email protected]>
For further information check:
http://www.uclinux.org/
Execution Finished, Exiting
Sash command shell (version 1.1.1)
/> cd bin
/bin> ./test
opened test.db successfully!
/bin>
成功执行:)超爽,哈哈!
五、把sqlite直接移植到uclinux,可以在那里直接执行sqlite test.db,现在不做了,以后需要的时候在加上,呵呵。
QQ:251059619
Blog:http://blog.chinaunix.net/u1/33990/
一、简单介绍
在用到数据库的嵌入式系统中,我们可以用开放源码的sqlite,下面我将介绍两种方法,一个是交叉编译,在主机上生成相应的库文件,这样在编译应用程序的时候,可以在PC上完成静态编译,这样的应用程序可以直接拿到romfs上在嵌入式环境下运行,第二个是把整个数据库移植到romfs,在uClinux下运行sqlite。
二、交叉编译工具的安装
在ftp://ftp.arm.linux.org.uk/pub/linux/arm/toolchain/cross-2.95.3.tar.bz2上下载cross-2.95.3.tar.bz2
#mkdir –p /usr/local/arm
#cd /usr/local/arm
#tar jxvf `/cross-2.95.3.tar.bz2 //直接解到压缩到这个目录下就完成了
这时候的gcc为 2.95.3/bin/arm-linux-gcc,而它的 include 为 2.95.3/arm-linux/include ,对应的 lib 为 2.95.3/arm-linux/lib,也就是说,如果此时有什么为交叉编译需要的库和头文件,就必须拷到这里面来。
把可行程序的路径加入到 PATH 中去
$cd $HOME
$vi .bashrc
在最后面加上一句
export PATH="$PATH:/sbin:/usr/local/arm/2.95.3/bin:/usr/local/bin:/usr/local"
保存,退出
$ source .bashrc
这样就完成了交叉编译工具的安装。三、sqlite的交叉编译
(本过程参照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
四、利用上面编译好的库来交叉编译个数据库测试程序
源代码如下:test.c
#include <stdio.h>
#include <sqlite3.h>
int main(int argc, char *argv[])
{
sqlite3 *db=NULL;
int rc;
rc = sqlite3_open("test.db", &db);
if( rc )
{
printf("cannot open test.db ");
sqlite3_close(db);
exit(1);
}
else
printf("opened test.db successfully!\n");
sqlite3_close(db);
return 0;
}
$ arm-elf-gcc -Wall -O2 -Wl, -elf2flt -o test test.c -lsqlite3 -L/home/yeshi/sqliteforuclinux/bld/lib -I/home/yeshi/sqliteforuclinux/bld/include -static
生成test文件,静态连接的。
小插曲:我开始的时候并不是用arm-elf-gcc,而是arm-linux-gcc,可是出现cannot find entry symbol lf2flt,原因是工具链有问题,需要打 elf2flt 的补丁才可以。我就不打了,直接用从www.uclinux.org上给的arm-elf-gcc:)
把test文件拷到romfs/bin,同时在该目录新建个test.db(测试用)
$ genromfs -v -V "ROMdisk" -f ./images/romfs.img -d /usr/local/src/uclinux-s3cev40/romfs
$......../skyeye_1_2_2_Rel/binary/skyeye -e linux-2.4.x/linux
Welcome to
____ _ _
/ __| ||_|
_ _| | | | _ ____ _ _ _ _
| | | | | | || | _ \| | | |\ \/ /
| |_| | |__| || | | | | |_| |/ \
| ___\____|_||_|_| |_|\____|\_/\_/
| |
|_|
GDB/ARMulator support by <[email protected]>
For further information check:
http://www.uclinux.org/
Execution Finished, Exiting
Sash command shell (version 1.1.1)
/> cd bin
/bin> ./test
opened test.db successfully!
/bin>
成功执行:)超爽,哈哈!
五、把sqlite直接移植到uclinux,可以在那里直接执行sqlite test.db,现在不做了,以后需要的时候在加上,呵呵。
相关阅读 更多 +