How to compile and build the SQLite library on windows XP and up


The SQLitePass library uses specific SQLite functions to retrieve schema information on an SQL statement.

These functions are :

    • sqlite3_column_database_name
    • sqlite3_column_database_name16
    • sqlite3_column_table_name
    • sqlite3_column_table_name16
    • sqlite3_column_origin_name
    • sqlite3_column_origin_name16
    • sqlite3_table_column_metadata

Unfortunately, they are not always available in the precompiled windows (dll) library available on the SQLite webpage.

In order to get these functions in our sqlite3.dll library, we need to compile the SQLite source code with the [SQLITE_ENABLE_COLUMN_METADATA] compiler directive.

This tutorial shows one simple way to achieve the library compilation. Feel free to post your comments if you are aware of a better "HowTo".

Now, If you want to compile your own SQLite library, follow this step by step tutorial :


Step 1 : Download and install a C - C++ compiler

Go to the Bloodshed webpage at http://www.bloodshed.net and download the latest Dev-C++ compiler version :

Dev-C++ 5.0 beta 9.2 (4.9.9.2) (9.0 MB) with Mingw/GCC 3.4.2




Or go directly to http://sourceforge.net and choose devcpp-4.9.9.2_setup.exe





Install the compiler :





Open the Dev-Cpp directory and create a new sqlite340 directory (Typically C:\Dev-Cpp\sqlitexxx where xxx represents the sqlite version.





Step 2 : Download the required SQLite files

Go to the SQLite webpage at http://www.sqlite.org/download.html and download the latest files versions directly in the sqlitexxx directory

you just created :


We need the sqlite.def file included in sqlitedll-xxx.zip to compile our library.


We need the sqlite.c and sqlite.h files included in sqlite-amalgation-xxx.zip to compile our library



Open the C++ IDE and select [ File | New | Project ]




Step 3 : Open the C++ IDE



Open the C++ IDE and select [ File | New | Project ]



Choose DLL, and C Project (NOT C++) and name it sqlite... or whatever you want.

Save your new project (sqlitexxx.dev) in your C:\Dev-Cpp\sqlitexxx directory.



Choose [ Project | Add to Project ] and add sqlite.c, sqlite.h and sqlite.def to your project window.












The files dll.h and dllmain.c will be automatically created by IDE.



Step 4 : Edit your project in the IDE


Edit the sqlite.def file and add the following lines to this file. (Copy them from here)

sqlite3_column_database_name
sqlite3_column_database_name16
sqlite3_column_table_name
sqlite3_column_table_name16
sqlite3_column_origin_name
sqlite3_column_origin_name16
sqlite3_table_column_metadata





Edit the sqlite.c file and add the line #define SQLITE_ENABLE_COLUMN_METADATA




Step 5 : Compile the library

Choose [ Project | Project Options]

Select Best optimization in compiler optimizations




add --def sqlite3.def in the linker options





You are ready to compile the sqlite library !

Choose [ Execute | Compile (ctrl + F9)]




The file sqlite340.dll is created in your project directory.




If you want to reduce the size of your file, use the strip.exe utility from a command line window, since the size is a lot larger than the original library available from sqlite.org (I don't know why, but I am not a C gourou and may be some more compiler optimizations are needed or the added functions are heavy...)




You can now use it, rename it ... or check the exported functions with the the DLL export viewer from http://www.nirsoft.net




Have fun and feel free to post your comments or tips on the forum.