Compiling - carlosbet/sqlcipher GitHub Wiki

How to compile SQLCipher 4.4.0 on Win64


Requeriments

1. Getting a Git Repository

git clone https://github.com/carlosbet/sqlcipher.git

Git Clone

At this moment (2020/06/13) this process works fine with the master branch of the repository. But always we can change to the v4.0.0 tag if we need to use the specific versión.

git tag | tail
git checkout tags v4.0.0

Git show last tags

Git checkout to 4.0.0 tag

2. Install ActiveTcl 8.6

Such as indicate in SQLCipher documentation:

SQLite does not require Tcl to run, but a Tcl installation is required by the makefiles (including those for MSVC). SQLite contains a lot of generated code and Tcl is used to do much of that code generation.

ActiveState offers a Tcl distribution (ActiveTcl) for Windows, Linux and Mac, pre-bundled with top Tcl/Tk modules. This distribution is free for development use. Just we download and install with default options (Install for all users, and accept the default path of C:\Tcl).

3. Install OpenSSL

OpenSSL does not provide pre-compiled binaries directly, but some people have offered to provide OpenSSL binary distributions for selected operating systems. In the [wiki of OpenSSL], we can obtain a list of these distributions.

For me, the first Shining Light Productions is the best option. We download Win64 OpenSSL v1.1.1g.

During installation, we change the destination folder to C:\dev\OpenSSL-Win64:

OpenSSL installation path

And change the location of the .DLLs to be inside the OpenSSL binaries (/bin) directory:

OpenSSL binaries directory

Finally, we install:

OpenSSL binaries directory

4. Edit Makefile.msc

Now we edit the file Makefile.msc to adapt this to our environment. I prefer work with a copy of original file...

We need to disable incremental linking to compile without errors. By default nmake use incremental linking, add /INCREMENTAL:NO to LDLFLAGS variable:

LDFLAGS = $(LDFLAGS) /INCREMENTAL:NO

LDLFLAGS Disable nmake incremental linking

Such as indicate in SQLCipher documentation:

Building SQLCipher is similar to compiling a regular version of SQLite from source a couple small exceptions:

  1. You must define SQLITE_HAS_CODEC and either SQLITE_TEMP_STORE=2 or SQLITE_TEMP_STORE=3`
  2. You will need to link against a support cryptograpic provider (OpenSSL, LibTomCrypt, CommonCrypto/Security.framework, or NSS)

We change -DSQLITE_TEMP_STORE from 1 to 2, add -DSQLITE_TEMP_STORE to the TCC and RCC variables and finally add -IC:\dev\OpenSSL-Win64\include to TCC and RCC variables:

TCC = $(TCC) -DSQLITE_TEMP_STORE=2
RCC = $(RCC) -DSQLITE_TEMP_STORE=2

TCC = $(TCC) -DSQLITE_HAS_CODEC
RCC = $(RCC) -DSQLITE_HAS_CODEC

TCC = $(TCC) -IC:\dev\OpenSSL-Win64\include
RCC = $(RCC) -IC:\dev\OpenSSL-Win64\include

TCC and RCC flags

Add /LIBPATH:C:\dev\OpenSSL-Win64\lib /LIBPATH:C:\dev\OpenSSL-Win64\lib\VC to the LTLIBPATHS variable, then add capi.lib, padlock.lib, libcrypto.lib, libssl.lib to the LTLIBS variable. Note that these filenames are just the list of files from C:\dev\OpenSSL-Win64\lib. If you have different files in your directory, use your filenames instead.

LTLIBPATHS = $(LTLIBPATHS) /LIBPATH:C:\dev\OpenSSL-Win64\lib /LIBPATH:C:\dev\OpenSSL-Win64\lib\VC
LTLIBS = $(LTLIBS) capi.lib padlock.lib libcrypto.lib libssl.lib

LTLIBPATHS and LTLIBS OpenSSL libs

5. Change Names (Optional)

By default, the name of the binaries is SQLite. We will change this name to SQLCipher. For this, we change the following lines:

  • SQLITE3DLL - Should be changed to sqlcipher

Change DLL Name

  • SQLITE3LIB - Should be changed to sqlcipher

Change Import Library Name

  • SQLITE3EXE - Should be changed to sqlcipher

Change Shell Executable Name

  • SQLITE3EXEPDB - Should be changed to sqlcipher

Change PDB Name

  • Finally we do a case sensitive & whole word search-n-replace, changing sqlite3.def to sqlcipher3.def (you should find 5 instances):

Change .def file names

6. Compile SQLCipher

Open x64 Native Tools Command Prompt for VS 2019, create a directory to compile and execute nmake to compile SQLCipher:

nmake /f ..\sqlcipher\MyMakefile.msc TOP=..\sqlcipher

nmake compile SQLCipher

And... Yabba Dabba Doo SQLCipher successfully compiled :stuck_out_tongue_closed_eyes: :stuck_out_tongue_closed_eyes: :stuck_out_tongue_closed_eyes:

SQLCipher compile results

Copy libcrypto-1_1-x64.dll and libssl-1_1-x64.dll to results directory to ensure all work:

copy c:\dev\OpenSSL-Win64\*.dll .\

Copy OpenSSL DLLs

Enjoy!! :sunglasses:

Running SQLCipher

Runnig SQLCipher

PD:Thanks a lot to the SQLite community and a Zetetic and its community for offering these products as open-source code. :clap: :clap: :clap: