sqlite 交叉编译-转

近段时间在学数据库,因为自身需求,所以注重研究了点嵌入式sqlite数据库,
SQLite,是一款轻型的数据库,是遵守ACID的关联式数据库管理系统,它的设计目标是嵌入式的,而且目前已经在很多嵌入式产品中使用了它,
它占用资源非常的低,在嵌入式设备中,可能只需要几百K的内存就够了。它能够支持Windows/Linux/Unix等等主流的操作系统,
同时能够跟很多程序语言相结合,比如 Tcl、C#、PHP、Java等,还有ODBC接口,
同样比起Mysql、PostgreSQL这两款开源世界著名的数据库管理系统来讲,它的处理速度比他们都快。
自我感觉用起来很high的...
就不扯了,下面言归正传:
下面就将sqlite移植到ARM开发板上的具体步骤贴下来,
在移植之前首先需要做的工作一是搭建PC端与ARM端数据共享机制,关于这个的方法很多,我在之前的文章中也就nfs共享的具体步骤做过详细的说明,
这里就不在累赘了。二是搭建交叉编译环境;
检测本机是否已经安装交叉编译环境可在终端中键入#arm-linux-gcc -v进行查看
获取sqlite源码包,源码包可到www.sqlite.org官方网站下载,我在此使用的是sqlite-3.6.18.tar.gz
1.将sqlite-3.6.18.tar.gz解压到/home目录下,并在sqlite-3.6.18目录下建立sqlite-arm-linux目录
#cd /home/sqlite-3.6.18
#mkdir sqlite-arm-linux
2.首先备份configure文件
#cp configure configure.old
3.修改configure文件,
#./configure --host=arm-linux --disable-tcl --prefix=/home/sqlite-3.6.18/sqlite-arm-linux/
4.修改Makefile文件
BBC = gcc -g -O2
5.编译并安装
#make && make install
6.为了减小执行文件大小,可用strip处理,去掉其中的调试信息
#cd /home/sqlite-3.6.18/sqlite-arm-linux/bin
#arm-linux-strip sqlite3
7.而后进行移植
对库的拷贝时要加上-arf选项,因为libsqlite3.so, libsqlite3.so.0是链接到libsqlite3.so.0.8.6的
#cd /home/sqlite-3.6.18/sqlite-arm-linux/lib
#cp -arf libsqlite3.so, libsqlite3.so.0, libsqlite3.so.0.8.6 /usr/yang(共享目录)
#cd /home/sqlite-3.6.18/sqlite-arm-linux/bin
#cp sqlite3 /usr/yang(共享目录)
8.在开发板终端中将三个库文件拷贝到其库中,而后即可使用sqlite了。
但要提醒一点的就是,sqlite跟MySQL....有点不一样哟..
我刚开始玩的时候首先就输入了show databases; 结果让我很揪心,所以在大家用sqlite之前还是建议先学好用法.
我相信你会在嵌入式数据库中玩的很high的....
-----------------------------------------------------------------------------------------
采用的是sqlite-autoconf-3080002.tar.gz

解压 tar xvf sqlite-autoconf-3080002.tar.gz

进入 cd sqlite-autoconf-3080002/


采用的是 arm-none-linux-gnueabi-gcc(g++)编译。


./configure --host=arm-none-linux-gnueabi --prefix=/home/liukang/sqlite-arm-linux LD=arm-none-linux-gnueabi-ld
make

make install
生成libsqlite3.a 静态库文件,在/home/liukang/sqlite-arm-linux/lib/ 文件夹下。



./configure --host=arm-none-linux-gnueabi --prefix=/home/liukang/sqlite-arm-linux-so --disable-tcl
make
make install
生成四个文件,在/home/liukang/sqlite-arm-linux-so/lib/ 文件夹下:
libsqlite3.la

libsqlite3.so -> libsqlite3.so.0.8.6
libsqlite3.so.0 -> libsqlite3.so.0.8.6
libsqlite3.so.0.8.6


压缩: arm-none-linux-gnueabi-strip libsqlite3.so.0.8.6
cplibsqlite3.so 到你工程所需的库文件夹下。
cplibsqlite3.so.0到ARM板上的/lib/下
cp bin/sqlite3 到ARM板上的/usr/bin/下

编译时 加上-lsqlite3,用到的是 libsqlite3.so
在ARM板上运行时,将 libsqlite3.so.0 放到 /lib/ 下即可使用动态库。



-------------------------------------------------------------------------------------------
【sqlite 交叉编译-转】 up vote2down votefavorite
Cross compile SQLite for ARM
I am using SQLite 3 for Database management in my ARM9 based microprocessor.
I want to cross compile the latest version of the SQLite 3 for my project in Linux (Ubuntu 10.04). I am using the arm-none-linux-gnueabi-gcc compiler for development.
I tried to cross compile using following commands,
Downloaded the sqlite-amalgamation-3.7.0.tar I extract it and then write the following command on Terminal,
sudo ./configure --exec-prefix=/media/8CCC8E9BCC8E7F68/SQLIte3/sqliteinstall/--host=arm --target=arm CC=/opt/arm-2011.03/bin/arm-none-linux-gnueabi-gcc AR=/opt/arm-2011.03/bin/arm-none-linux-gnueabi-ar STRIP=/opt/arm-2011.03/bin/arm-none-linux-gnueabi-strip RANLIB=/opt/arm-2011.03/bin/arm-none-linux-gnueabi-ranlib CFLAGS="-Os"


还是老外牛叉 国产大多啰嗦一通 不能用
--target=arm 3.7.12版本已经没有这个选项按照上面方式不能生成动态库
所以--host=arm --target=arm 改为--host=arm-linux 这样就ok了
--exec-prefix 改为--prefix 不然不生成 include man 文件夹
./configure --prefix=/media/8CCC8E9BCC8E7F68/SQLIte3/sqliteinstall/--host=arm-linux CC=/opt/arm-2011.03/bin/arm-none-linux-gnueabi-gccCFLAGS="-Os" 生成静态的一样大小 动态库 可执行文件比较大 还是上面学全的方式好

(1)--prefix=<目录>:指定Apache的安装目录。
(2)--exec-prefix=<目录>:指定Apache的顶级安装目录,使用该参数时可以配合以下参数将Apache的文件安装到不同的目录,可以方便地在不同主机之间共享Apache相关的文件。该参数的默认值为--prefix参数指定的目录。





It successfully cross compiled the SQLite.
Then,

sudo make

command.
It successfully run. Now make install command.
It did not give me an error but when I went to the config.log file i found there is some sentences as following,
1.conftest.c:17:7: error: size of array 'off_t_is_large' is negative 2.conftest.c:12:28: fatal error: ac_nonexistent.h: No such file or directory compilation terminated. 3.conftest.cpp:23:28: error: ac_nonexistent.h: No such file or directory 4.conftest.c:67:13: error: invalid type argument of unary '*' (have 'int')

I doubt that weather it has been cross compiled properly or not. I can not understand.
I inserted the library on my board it works fine but the problem is that the speed got very slow. I think there is some problem that i have not set any flags for the GCC compiler.
I could not find any options.How I can set the particular flags for the GCC compiler so that unnecessary features can be omitted.
cross-compilation
shareimprove this question
edited Jan 5 at 0:39




Braiam
16.7k93167
asked Mar 15 '13 at 4:55




Parthiv Shah
266

I think there is some issue that it can not find the compiler path ,So i find where my GCC compiler is installed and then reconfigured it with the following command. ./configure --host=arm CC=/opt/arm-2011.03/bin/arm-none-linux-gnueabi-gcc AR=/opt/arm-2011.03/bin/arm-none-linux-gnueabi-ar STRIP=/opt/arm-2011.03/bin/arm-none-linux-gnueabi-strip RANLIB=/opt/arm-2011.03/bin/arm-none-linux-gnueabi-ranlib CFLAGS="Os" –Parthiv Shah Mar 15 '13 at 7:13

But it gave me an error : C Compiler cannot create executables. –Parthiv Shah Mar 15 '13 at 7:16

Right now I am getting an error in the cross compilation. It gave me an error that "C COMPILER CANNOT CREATE EXECUTABLES" –Parthiv Shah Mar 15 '13 at 8:12
2
Yes, but what I mean is: don't add this to the comments. Edit the question itself such that it reflects exactly where you are stuck. –zwets Mar 15 '13 at 8:20

Hey I got some useful information about the Cflags and Finally Configueed my SQLIte 3.7.15.2 with the Most appropriate parameters and features. Please go through the Below link for CFALGS.gcc.gnu.org/onlinedocs/gcc/ARM-Options.html –Parthiv Shah Mar 18 '13 at 9:19
show 1 more comment

1 Answer
ACTIVEOLDESTVOTES

up vote0down vote
This worked for me (and it works to cross compile most other third-party software):
$ export PATH=$PATH:$ cd $ ./configure --prefix="" --host=arm-unknown-linux-gnueabi

Add your CFLAGS and other configuration parameters to the configuration parameters. E.g.,
$ ./configure --prefix="" --host=arm-unknown-linux-gnueabi -CFLAGS="-Os" --enable-threadsafe

If in your case the target system is specified by arm-none-linux-gnueabi, replace the host in the above example:
$ ./configure --prefix="" --host=arm-none-linux-gnueabi -CFLAGS="-Os" --enable-threadsafe

The paths to GCC, CC, AR, ... will be found from the host you've set.
shareimprove this answer


    推荐阅读