linux sqlite 静态库

转载 2011年01月11日 20:05:00



----------------------- Page 1-----------------------

1、在Redhat Linux9 上用arm-linux-gcc编译成功sqlite-3.3.6 静态库版本。

2、在Redhat Linux9 上用arm-linux-gcc编译成功基于sqlite3 静态库的应用程序。

Compile SQLite using the cross-compiler such as arm-linux-gcc

first, get sqlite-3.3.6.tar.gz from

unzip it,

#tar -zxvf sqlite-3.3.6.tar.gz

change into the sqlite-3.3.6 directory

cd sqlite-3.3.6

make a new directory such as 'build' under sqlite-3.3.6 directory,

open the configure-script using your favorite text-editor ,such as:

#vi configure

I recomamnd that you make a copy of configure before editing the configure file

cp configure configure.old

and edit the configure.

Comment out the following commands by putting a '#' in front of them(looks like):

#if test "$cross_compiling" = "yes"; then

# { { echo "$as_me:$LINENO:: 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; }; }


. . .


# test "$cross_compiling" = yes &&

# { { echo "$as_me:$LINENO:: 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; }; }

. . .


# test "$cross_compiling" = yes &&

----------------------- Page 2-----------------------

# { { echo "$as_me:$LINENO:: 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; }; }

Save the configure script, change into the build directory you created and call the edited configure script from the sqlite

directory by using the following option:

../sqlite/configure --disable-tcl --host=arm-linux

After that configure should have created a Makefile and a libtool script in your build directory.

Open the Makefile using your favorite text editor and find the following lines:

BCC = arm-linux-gcc -g -O2

change to

BCC = gcc -g -O2

The reason for these changes is that the created files have to be executed on the PC during the compilation, so we have to

compile them with the standard gcc and not the arm-linux-gcc.

if you want compile static library version of sqlite3(only one execute file for distribution) on ARM, edit Makefile ,


sqlite3$(TEXE): $(TOP)/src/shell.c .libs/ sqlite3.h

change to

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


-o $@ $(TOP)/src/shell.c .libs/ /

change to

-o $@ $(TOP)/src/shell.c .libs/libsqlite3.a /

save and quit editor

run 'make' command to create the sqlite3 execute file, after a successful compile,Now you should find a hiden “.libs”

directory in your build directory containing sqlite shared object files, like or static libray files like

libsqlite3.a .

run 'arm-linux-strip sqlite3' to decrease the execute file size.

upload the sqlite3 to target ARM9 board by any FTP client and make it executive:

----------------------- Page 3-----------------------

on ARM9 board with terminal or telnet ,run

chmod 775 sqlite3

and then run sqlite3 like this

sqlite3 ex2

,if you see the following messages:

SQLite version 3.3.6

Enter ".help" for instructions


input some commands to do something,

sqlite> create table tbl(one varchar(10),two smallint);

sqlite> insert into tbl values('hello',10);

sqlite> insert into tbl values('goodbye',20);

sqlite> .quit

more commands , please visit for details

then use 'ls ex2' to list files in currect directory,

if you see 'ex2' file,

congratulations,you have successfully making a standalone 'sqlite3'.

next step we should compile the example code on's quickstart page

make a 'test.c' file in 'build' directory, content as showed:

#include <stdio.h>

#include "sqlite3.h" /* orignal is <sqlite3.h> */

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

int i;

for(i=0; i<argc; i++){

printf("%s = %s/n", azColName[i], argv[i] ? argv[i] : "NULL");



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]);



rc = sqlite3_open(argv[1], &db);

if( rc ){

----------------------- Page 4-----------------------

fprintf(stderr, "Can't open database: %s/n", sqlite3_errmsg(db));




rc = sqlite3_exec(db, argv[2], callback, 0, &zErrMsg);

if( rc!=SQLITE_OK ){

fprintf(stderr, "SQL error: %s/n", zErrMsg);




return 0;


save and quit editor,

#arm-linux-gcc test.c -L.libs -lsqlite3 -static

explaination: -L.libs show that the lib searching path is '.libs'

'-lsqlite3 -static' show that the lib name is libsqlite3.a,the 'lib' and '.a' is added by linker.

with the above command ,we can compile a standalone application with sql databse supported.

use arm-linux-strip to decrease its size:

arm-linux-strip a.out

upload to ARM9 board, make it runable and test it:

[root@fa fa]# a.out ex "select * from tbl"

one = hello

two = 10

one = goodbye

two = 20

[root@fa fa]#

if you see the above result , ok you make it.


wish the article is usefull for you!


在我的Ubuntu上移植SQLite3.3.6,编译成静态库   2009-10-28 17:06:21|  分类: Unix/Linux/Windo|举报|字号 订阅 ...
  • lxlll1985
  • lxlll1985
  • 2014年04月07日 19:57
  • 395

sqlite3 编译静态库

因为cocos2d-x 没有提供 sqlite3的ios android的库( ios sdk和android sdk都自带)。自己正好学习下,怎么做库。 xcode:Version 5.1.1  ...
  • lile1234_show
  • lile1234_show
  • 2014年12月19日 16:07
  • 1577

linux sqlite 静态库

linux sqlite 静态库
  • zhangxiaonanwin
  • zhangxiaonanwin
  • 2011年01月11日 20:05
  • 947


//---------------------------------------------------- //AUTHOR: lanyang123456 //DATE: 2012-6-20 ...
  • lanyang123456
  • lanyang123456
  • 2012年06月20日 17:58
  • 7109

Visual C++ Tips: 创建 SQLite 静态库

编译 SQLite 静态库。 本文所使用编译工具软件:Visual Studio 2015 Community; SQLite 版本:3.9.2。...
  • XinYaping
  • XinYaping
  • 2015年11月14日 23:15
  • 1249

linux下 编译和使用静态库

创建并使用静态库 第一步:编辑源文件,test.h test.c main.c。其中main.c文件中包含main函数,作为程序入口;test.c中包含main函数中需要用到的函数。 vi...
  • xuplus
  • xuplus
  • 2016年07月29日 15:51
  • 6091


  • wp1027322856
  • wp1027322856
  • 2017年08月27日 22:27
  • 90

如何查看静态库内容 Unix/Linux

如何查看静态库内容 Unix/Linux 以下从最好情况->最坏情况: 1. 最好知道静态库的原文件(.c),要是知道声明文件(.h)也比较好。 2. ar -t YourFil...
  • changli_90
  • changli_90
  • 2013年06月26日 13:57
  • 2891


在项目中遇到隐蔽一个问题,如下: 按上面的方式进行链接,提示一直找不到-lipc_server,后面发现是由于生成的库没有加lib前缀导致的,应该要这种格式libipc_server.a,但是另一种...
  • aguei868
  • aguei868
  • 2016年09月22日 16:53
  • 888

Linux 创建静态库以及静态库的使用

目录: 1 手动建立静态库 2 静态库的使用 3 通过makefile文件建立静态库 1 手动建立静态库 将建立一个简单的静态库 -1: 将所需的源文件编译成目标文件 ------...
  • alex_my
  • alex_my
  • 2015年02月08日 12:08
  • 1662
您举报文章:linux sqlite 静态库