Sqlite Compile
Sqlite Compile
Sqlite Compile
All three of the above source files are contained in the amalgamation tarball av
ailable on the download page.
To build the CLI, simply put these three files in the same directory and compile
them together. Using MSVC:
cl shell.c sqlite3.c -Fesqlite3.exe
On unix systems (or on Windows using cygwin or mingw+msys) the command typically
looks something like this:
gcc shell.c sqlite3.c -lpthread -ldl
The pthreads library is needed to make SQLite threadsafe. But since the CLI is s
ingle threaded, we could instruct SQLite to build in a non-threadsafe mode and t
hereby omit the pthreads library:
gcc -DSQLITE_THREADSAFE=0 shell.c sqlite3.c -ldl
The -ldl library is needed to support dynamic loading, the sqlite3_load_extensio
n() interface and the load_extension() SQL function. If these features are not r
equired, then they can be omitted using SQLITE_OMIT_LOAD_EXTENSION compile-time
option:
gcc -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION shell.c sqlite3.c
One might want to provide other compile-time options such as -DSQLITE_ENABLE_FTS
4 or -DSQLITE_ENABLE_FTS5 for full-text search, -DSQLITE_ENABLE_RTREE for the R*
Tree search engine extension, -DSQLITE_ENABLE_JSON1 to include JSON SQL function
s, or -DSQLITE_ENABLE_DBSTAT_VTAB for the dbstat virtual table. In order to see
extra commentary in EXPLAIN listings, add the -DSQLITE_ENABLE_EXPLAIN_COMMENTS o
ption. On unix systems, add -DHAVE_USLEEP=1 if the host machine supports the usl
eep() system call. Add -DHAVE_READLINE and the -lreadline and -lncurses librarie
s to get command-line editing support. One might also want to specify some compi
ler optimization switches. (The precompiled CLI available for download from the
SQLite website uses "-Os".) There are countless possible variations here. A comm
and to compile a full-featured shell might look something like this:
gcc -Os -I. -DSQLITE_THREADSAFE=0 -DSQLITE_ENABLE_FTS4 \
-DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_JSON1 \
-DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
-DHAVE_USLEEP -DHAVE_READLINE \
shell.c sqlite3.c -ldl -lreadline -lncurses -o sqlite3
The key point is this: Building the CLI consists of compiling together two C-lan
guage files. The shell.c file contains the definition of the entry point and the
user input loop and the SQLite amalgamation sqlite3.c contains the complete imp
lementation of the SQLite library.
Compiling The TCL Interface
The TCL interface for SQLite is a small module that is added into the regular am
algamation. The result is a new amalgamated source file called "tclsqlite3.c". T
his single source file is all that is needed to generate a shared library that c
an be loaded into a standard tclsh or wish using the TCL load command, or to gen
erate a standalone tclsh that comes with SQLite built in. A copy of the tcl amal
gamation is included on the download page as a file in the TEA tarball.
To generate a TCL-loadable library for SQLite on Linux, the following command wi
ll suffice: