Guide for Sqlite Compilation Procedure

admin | May 29th, 2015 | General

In our last Blog we discussed about The Sqlite and its Uses know we will move forward towards another interesting and important topic in Sqlite that is Sqlite Compilation Options. The Sqlite compilation is the method of transforming program from source code to object code just like we do it in other types of programming languages. Source code is processed through several stages before it is converted to executable programs, including compilation as one of the stages which translates the high-level language instruction sets to object code. The section below will guide you to perform the Sqlite compilation options in detail. First of all we will cover the principle needs for all the OS and then we will explain Sqlite Compilation procedure for Windows in detail.

Source Files and Amalgamation Concept

Sqlite is assembled with more than 100 files of C code and scripts over multiple directories. The Sqlite implements ANSI-C language, but many source code files are created for converting by auxiliary C programs and SED, TCL, and AWK scripts. To make it less complicated, Sqlite is available as an amalgamation source code file; sqlite3 C. The Sqlite can be built through the available source code files also, but it is not advised procedure.

Command-line Interface Compilation

Following source files are essential for command-line-interface;

  • c: Amalgamation source file.
  • h: Header files with sqlite3.c
  • c: Command-line interface application.

All these files are available on Sqlite site and can be downloaded easily. shell.c comprises the definition of main () routine and loop to which input has to be provided.

The source files mentioned above is put in the same directory in order to build CLI to build them all together. If you are using MSVC:

sqlite compiling code 1

Compilation Commands for Unix and Windows (with MinGW+msys or Cygwin) systems;

sqlite compiling code 2

Command for omitting the threads library;

sqlite compiling code 3

The –ldl library can be essential to support dynamic loading, load extension () SQL function and sqlite3 load extension (). In case these features are not needed, it can be omitted using SQLITE OMIT LOAD EXTENSION compile-time option;

sqlite compiling code 4

CLI building takes compilation of two C-language files; shell.c file has the entry point definition and user-side input loop. sqlite3.c the amalgamation source file on the other hand comprises complete implementation of Sqlite library.

TCL Interface Compilation

The Sqlite TCL interface is another small module which is usually added to regular amalgamation with a resultant source file known as “tclsqlite3.c“. A single source file is required for generation of shared library. This TCL amalgamation is available for download as well.

Command for generating Sqlite TCL-loadable library on Linux;

Sqlite compiling code 5

Compiler invocation for generating standalone tclsh statically linked with Sqlite;

sqite compiling code 6

For Windows and Mac OS X it is better to use configure script and create a file which is included with TEA tarball.

Building Amalgamation

Amalgamation for Sqlite application is already provided on the download page and is sufficient for users. But many users or projects might need it to customize more to build own amalgamations especially to utilize certain compile-time options. The procedure to build amalgamation of your own, you need to first download original source files in Unix/Unix-like development platform. Do not download an amalgamation and download original source files only. If you have stored Sqlite source tree in “ABC” directory, opt for constructing amalgamation in parallel directory as “XYZ”. Create a Makefile by making copies of one template Makefiles at top of the source tree. Then in order to include the desired compile-time options hand edit Makefile. Then run:

sqlite cxompiling code 7

For Windows systems with MSVC;

sqlite compilation options code 8

The regular “sqlite3.c” amalgamation source file, its header “sqlite3.h“, and the “tclsqlite3.c” amalgamation source file including the TCL interface will be constructed with “sqlite3.c’ make target. Then the required files can be written to project directories compiled as per need.

Building Windows DLL

Windows users can build DLL of Sqlite by downloading relevant amalgamated source code files, sqlite3.h and sqlite3.c. Once the source files are downloaded they must be stored in the working directory. Then a DLL can be generated with MSVC through below mentioned command from MSVC Native Tools Command Prompt;

sqlite compiling code 9

For MinGW compiler, the command is;

sqlite compiling code 10

Sqlite in Windows

Windows users can follow the below mentioned steps to compile Sqlite program and construct a database in a Sqlite application through command prompt. Getting Sqlite installed on Windows is very easy. For this download the amalgamation provided for Windows users on www.sqlite.org site.

 sqlite compilation option code 11

    • Once downloaded, store the executable file in C drive with a folder named as Extract from downloaded set-up and run the executable file.
    • Now open CMD from Start menu and perform the coding as shown in the image. Here a database named company has been created as company.db.
    • In this database we have created a table employee with attributes as empid (employee id), name, and title. Using insert option we have inserted entries for three employees.
    • You can check the entries through command select * from employee. This will show up entries made by you in a systematic manner.

sqlite compile code 12

You can also check at the same folder location of your system where execution file was copied (C Drive Sqlite folder) a database with the same name will be created. You can also view its content using any Sqlite browser like add-in available with Mozilla as Sqlite Manager. This add-in can be used to manage any Sqlite database available on your system. It is easy to get this add-in installed and even easier to use. You can view the database created by you in this DB Browser which will appear like below shown image.

  • sqlite compilation option code 13Name, Type and Schema can also be viewed using this DB browser.

    Conclusion

    Sqlite application can be compiled on various Operating Systems through various compilation techniques. In order to feed required compile-time options, you can prefer amalgamation process, but make sure to download original source files to build amalgamation. Windows users can however, prefer getting downloaded precompiled binary files, or prefer any one from several other options available like downloading source files, getting Sqlite DLL, building Sqlite DLL with Microsoft Visual C++, or building Sqlite with MinGW. You can also explore about Sqlite in more practical manner by using a free utility such as Sqlite Database Viewer. This utility will help you by making you view all the Sqlite related components and their file structure in free.

Disclaimer : – © 2020 Sqlite Viewer is an independent provider of Sqlite products & services. Sqlite Viewer is not in affiliation with any of the third–party organizations unless it is expressed explicitly. Read More...