[sqlite] Reducing compiled size

104 views
Skip to first unread message

Dave Hope

unread,
Jul 25, 2011, 10:39:16 AM7/25/11
to sqlite...@sqlite.org
Hi all,

I read on the sqlite website that the compiled size can be reduced to
275KiB ( http://www.sqlite.org/different.html#small ), however I'm
struggling to get it much below 500 KiB using the SQLITE_OMIT_*
options. I'm producing my own amalgamation, which I believe you can
use the OMIT options with:

"Special versions of the SQLite amalgamation that do work with a
predetermined set of SQLITE_OMIT_* options can be generated." (
http://www.sqlite.org/compile.html#omitfeatures ).

Here's what I'm doing to compile:

./configure CFLAGS="-DSQLITE_OMIT_ALTERTABLE -DSQLITE_OMIT_ANALYZE
-DSQLITE_OMIT_ATTACH -DSQLITE_OMIT_AUTHORIZATION
-DSQLITE_OMIT_AUTOINCREMENT -DSQLITE_OMIT_AUTOMATIC_INDEX
-DSQLITE_OMIT_AUTORESET -DSQLITE_OMIT_AUTOVACUUM
-DSQLITE_OMIT_BETWEEN_OPTIMIZATION -DSQLITE_OMIT_BLOB_LITERAL
-DSQLITE_OMIT_BTREECOUNT -DSQLITE_OMIT_BUILTIN_TEST -DSQLITE_OMIT_CAST
-DSQLITE_OMIT_CHECK -DSQLITE_OMIT_COMPILEOPTION_DIAGS
-DSQLITE_OMIT_COMPLETE -DSQLITE_OMIT_DATETIME_FUNCS
-DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_EXPLAIN
-DSQLITE_OMIT_FLAG_PRAGMAS -DSQLITE_OMIT_FLOATING_POINT
-DSQLITE_OMIT_FOREIGN_KEY -DSQLITE_OMIT_GET_TABLE
-DSQLITE_OMIT_INCRBLOB -DSQLITE_OMIT_INTEGRITY_CHECK
-DSQLITE_OMIT_LIKE_OPTIMIZATION -DSQLITE_OMIT_LOAD_EXTENSION
-DSQLITE_OMIT_LOCALTIME -DSQLITE_OMIT_MEMORYDB
-DSQLITE_OMIT_OR_OPTIMIZATION -DSQLITE_OMIT_PAGER_PRAGMAS
-DSQLITE_OMIT_PRAGMA -DSQLITE_OMIT_PROGRESS_CALLBACK
-DSQLITE_OMIT_QUICKBALANCE -DSQLITE_OMIT_REINDEX
-DSQLITE_OMIT_SCHEMA_PRAGMAS -DSQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
-DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_TCL_VARIABLE
-DSQLITE_OMIT_TEMPDB -DSQLITE_OMIT_TRACE -DSQLITE_OMIT_TRIGGER
-DSQLITE_OMIT_TRUNCATE_OPTIMIZATION -DSQLITE_OMIT_UTF16
-DSQLITE_OMIT_VACUUM -DSQLITE_OMIT_VIEW -DSQLITE_OMIT_VIRTUALTABLE
-DSQLITE_OMIT_WAL -DSQLITE_OMIT_WSD -DSQLITE_OMIT_XFER_OPT"

make sqlite3.c "-DSQLITE_OMIT_ALTERTABLE -DSQLITE_OMIT_ANALYZE
-DSQLITE_OMIT_ATTACH -DSQLITE_OMIT_AUTHORIZATION
-DSQLITE_OMIT_AUTOINCREMENT -DSQLITE_OMIT_AUTOMATIC_INDEX
-DSQLITE_OMIT_AUTORESET -DSQLITE_OMIT_AUTOVACUUM
-DSQLITE_OMIT_BETWEEN_OPTIMIZATION -DSQLITE_OMIT_BLOB_LITERAL
-DSQLITE_OMIT_BTREECOUNT -DSQLITE_OMIT_BUILTIN_TEST -DSQLITE_OMIT_CAST
-DSQLITE_OMIT_CHECK -DSQLITE_OMIT_COMPILEOPTION_DIAGS
-DSQLITE_OMIT_COMPLETE -DSQLITE_OMIT_DATETIME_FUNCS
-DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_EXPLAIN
-DSQLITE_OMIT_FLAG_PRAGMAS -DSQLITE_OMIT_FLOATING_POINT
-DSQLITE_OMIT_FOREIGN_KEY -DSQLITE_OMIT_GET_TABLE
-DSQLITE_OMIT_INCRBLOB -DSQLITE_OMIT_INTEGRITY_CHECK
-DSQLITE_OMIT_LIKE_OPTIMIZATION -DSQLITE_OMIT_LOAD_EXTENSION
-DSQLITE_OMIT_LOCALTIME -DSQLITE_OMIT_MEMORYDB
-DSQLITE_OMIT_OR_OPTIMIZATION -DSQLITE_OMIT_PAGER_PRAGMAS
-DSQLITE_OMIT_PRAGMA -DSQLITE_OMIT_PROGRESS_CALLBACK
-DSQLITE_OMIT_QUICKBALANCE -DSQLITE_OMIT_REINDEX
-DSQLITE_OMIT_SCHEMA_PRAGMAS -DSQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
-DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_TCL_VARIABLE
-DSQLITE_OMIT_TEMPDB -DSQLITE_OMIT_TRACE -DSQLITE_OMIT_TRIGGER
-DSQLITE_OMIT_TRUNCATE_OPTIMIZATION -DSQLITE_OMIT_UTF16
-DSQLITE_OMIT_VACUUM -DSQLITE_OMIT_VIEW -DSQLITE_OMIT_VIRTUALTABLE
-DSQLITE_OMIT_WAL -DSQLITE_OMIT_WSD -DSQLITE_OMIT_XFER_OPT"

Any suggestions as to where I'm going wrong?

Thanks

Dave
_______________________________________________
sqlite-users mailing list
sqlite...@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Stephan Beal

unread,
Jul 25, 2011, 10:46:04 AM7/25/11
to General Discussion of SQLite Database
On Mon, Jul 25, 2011 at 4:39 PM, Dave Hope <da...@davehope.co.uk> wrote:

> make sqlite3.c "-DSQLITE_OMIT_ALTERTABLE -DSQLITE_OMIT_ANALYZE
>

Shouldn't that be:

make sqlite3.c CPPFLAGS="..."

?

Make doesn't understand -D (no, that's not a smiley).

--
----- stephan beal
http://wanderinghorse.net/home/stephan/

Dave Hope

unread,
Jul 25, 2011, 10:51:33 AM7/25/11
to General Discussion of SQLite Database
Hi Stephan,

I initially added these to the Makefile, but looking at the mailing
list suggested otherwise:

http://www.mail-archive.com/sqlite...@sqlite.org/msg37813.html

Thanks

Dave

Stephan Beal

unread,
Jul 25, 2011, 10:55:56 AM7/25/11
to General Discussion of SQLite Database
On Mon, Jul 25, 2011 at 4:51 PM, Dave Hope <da...@hope.mx> wrote:

> Hi Stephan,
>
> I initially added these to the Makefile, but looking at the mailing
> list suggested otherwise:
>
> http://www.mail-archive.com/sqlite...@sqlite.org/msg37813.html


That post says to use:

make "OPTS=-..."

So it seems that OPTS= is missing.

Dave Hope

unread,
Jul 25, 2011, 11:06:31 AM7/25/11
to General Discussion of SQLite Database
Thanks Stephan

Sorry, you're quite right. I was actually using OPTS="" but omitted it
when I pasted it into my e-mail.

Thanks

Dave

Richard Hipp

unread,
Jul 25, 2011, 11:07:56 AM7/25/11
to General Discussion of SQLite Database
On Mon, Jul 25, 2011 at 10:39 AM, Dave Hope <da...@davehope.co.uk> wrote:

> Hi all,
>
> I read on the sqlite website that the compiled size can be reduced to
> 275KiB ( http://www.sqlite.org/different.html#small ), however I'm
> struggling to get it much below 500 KiB using the SQLITE_OMIT_*
> options. I'm producing my own amalgamation, which I believe you can
> use the OMIT options with:
>

So I type:

gcc -Os -c sqlite3.c; size sqlite3.o

And on Linux with gcc 4.1.0 I get 333802 bytes. This is without any OMIT
options. And you cannot get it below 500KB? What compiler are you using?


--
D. Richard Hipp
d...@sqlite.org

Dave Hope

unread,
Jul 25, 2011, 11:16:58 AM7/25/11
to General Discussion of SQLite Database
Hi Richard,

I'm using gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5). Also tried with
VC9 which yields very similar sizes.

$ gcc main.c sqlite3.c -lpthread -ldl
$ size a.out
text data bss dec hex filename
514475 3688 1168 519331 7eca3 a.out

It looks like this could have been because I wasn't optimizing for size:

$ gcc main.c sqlite3.c -lpthread -ldl -Os
$ size a.out
text data bss dec hex filename
326487 3588 1000 331075 50d43 a.out

Thanks for pointing out what I missed,

Dave

Baruch Burstein

unread,
Jul 25, 2011, 3:11:47 PM7/25/11
to General Discussion of SQLite Database
For the record, I know that the documentation says the OMIT_* flags don't
work with the regular amalgamation, but I have in fact used many of them and
they seem to work. Two that only partially worked (a bug?) are
SQLITE_OMIT_AUTOVACUUM and SQLITE_OMIT_AUTHORIZATION (I am not sure about
that second one, as I am writing this from memory. I think it was that one)
They gave a warning when compiling sqlite3.c and an error when linking it to
my program.
Reply all
Reply to author
Forward
0 new messages