附註:若 SQLite 版本大於 3.6.20,則無需參考本文。
目標平台:loongson 1B
目標開發板架構:mipsel 架構
編譯平台:Ubuntu 13.04
交叉工具鏈:gcc-4.3-ls232-softfloat
本文記錄在 loongson 上移植 sqlite3 的完整過程,所有操作均在 root 用戶下進行。
先解壓源碼 sqlite 3.6.20.tar.gz,進入 sqlite3.6.20 文件夾後執行:
1)./configure --host=mipsel-linux(指定交叉編譯工具鏈) --prefix=/opt/mispel-linux-sqlite
2)make
3)make install
執行 make 時會出現以下錯誤:
libtool: link: mipsel-linux-gcc -shared .libs/tclsqlite.o …… -ltclstub8.5 ……
.../ld: skipping incompatible .../libtclstub8.5.a when searching for -ltclstub8.5
.../ld: cannot find -ltclstub8.5
collect2: ld returned 1 exit status
make: *** [libtclsqlite3.la] 錯誤 1
出現「skipping incompatible」通常是不同處理器架構引用了不屬於自身架構的庫。上例中,就是 mipsel 架構引用了 x86 架構的 libtclstub8.5。因此,需要原始碼交叉編譯一份 tclsh 才能解決。
解決方法:解壓 tcl8.5.15-src.tar.gz,進入源碼文件夾 tcl8.5.15,執行:
1)./configure --host=mipsel-linux --prefix=/opt/mipsel-linux-tclsh
2)make
3)make install
但在執行 ./configure 過程中又會出現以下錯誤:
fixstrtod.o: In function `fixstrtod': fixstrtod.c:(.text+0x0): multiple definition of `fixstrtod'
strtod.o: strtod.c:(.text+0x0): first defined here
collect2: ld returned 1 exit status
make: *** [libtcl8.5.so] 錯誤 1
此時執行下面兩句即可解決:
[root@CaM/opt/tcl-embedded/unix 11:45]#export ac_cv_func_strtod=yes
[root@CaM/opt/tcl-embedded/unix 11:46]#export tcl_cv_strtod_buggy=1
編譯安裝完成後,在 mipsel-linux-sqlite 目錄下會分別生成 bin、include 和 lib 目錄。把 bin/sqlite3 與 lib/libsqlite3.so.0.8.6 分別拷到文件系統的 /bin 與 /lib 目錄,並將 libsqlite3.so.0.8.6 更名為 libsqlite3.so.0,移植即告完成。