SQLite移植手記1

2021-09-08 15:53:48 字數 3517 閱讀 7073

sqlite實現了大部分sql92標準的sql語句,同時支援acid。還有其它許多特性這裡不做深究,因為這在嵌入式領域來說應該是夠用了。

我使用的還是當前最新版本:sqlite-3.3.7.tar.gz

(寫完的時候已經更新出3.3.8版本了,真快啊……)

安裝:

時間不多,簡單介紹安裝過程:

解壓sqlite到uclinux-dist/user/sqlite/

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

編譯:測試一下:

編寫乙個測試程式sqlitetest.c,**如下(來自官方quick start):

#include #include static int callback(void *notused, int argc, char **ar**, 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 $ 執行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

SQLite移植手記

前幾天成功地把berkeley db移植到uclinux上,雖然可以正常工作了,但是檔案還是太大了些。今天來試乙個稍微小一點的,它叫sqlite。sqlite實現了大部分sql92標準的sql語句,同時支援acid。還有其它許多特性這裡不做深究,因為這在嵌入式領域來說應該是夠用了。hily jian...

sqlite 的移植與安裝

標籤 sqlite3,linux 1.源 的獲取 sqlite是乙個功能強大 體積小運算速度快的嵌入式資料庫,採用了全c語言封裝,並提供了八十多個命令介面,可移植性強,使用方便。sqlite源 sqlite 3.6.17.tar.gz 2.sqlite移植到x86 for linux l解壓檔案 建...

sqlite移植到arm(一)

虛擬機器 redhat 5 arm linux gcc 3.4.6 專案需要 這個社群看看有沒有。2 將tar包放在虛擬機器的 opt下,解壓,並在同級目錄下建立build資料夾,用來放之後產生的四個包。3 進入解壓後的資料夾,執行 4 之後執行 5 最後執行 這個時候,你剛才建立的build資料夾...