Saturday, August 11, 2012

Compiling SQLCipher for Windows

SQLCipher is a great extension to the SQLite library. It can be used to encrypt the database when using the SQLite API. It can be compiled for the major platforms like Linux, Mac OS X, iOS, Android and Microsoft Windows.
It is very simple to compile SQLCipher, except for the Windows case, where it can take some more time to get a working library. I spent some hours to have a static library, and I suppose it might be useful to write it down to accelerate the process for anybody who needs it.

In this thread you can find some information on how to compile SQLCipher for Windows. Instead, I preferred to take a different way: I didn't bother compiling OpenSSL (which is needed to compile SQLCipher), and used cygwin to buil the SQLCipher library linking to OpenSSL.

Download SQLCipher sources

First of all download the SQLCipher sources, with a zip archive or from the git. Uncompress the sources somewhere (I'll refer to this path using <sqlcipher_sources>).

Download the OpenSSL library

You can either compile OpenSSL using the Microsoft compiler or mingw or you can download the library from this website. I'll refer to the path containing the libraries with <openssl_binaries>.

Download and setup cygwin

I used cygwin to compile SQLCipher. Download it from the website. When requested, install at least these packages:
  1. make
  2. nano (in case you need to edit)
  3. tcl: Tool Command Language
  4. gcc-mingw-core
  5. mingw-gcc-core
This should be sufficient.

Compile SQLCipher from the cygwin command line

I used MinGW to compile the sources. First of all set the correct C compiler that make will use to compile the sources:

export CC=i686-pc-mingw32-gcc

Now go to the SQLCipher directory:

cd sqlcipher_sources

and lunch the configure script. We will need to lunch it this way:

./configure --disable-tcl CFLAGS="-DSQLITE_HAS_CODEC -Iopenssl_binaries/include" LDFLAGS="openssl_binaries/lib/libeay32.lib /usr/lib/gcc/i686-pc-mingw32/4.5.2/libgcc.a"

This will create the Makefile. Now, you can use the make command to build the library.
At a certain point, I got this message:

libtool: link: i686-pc-mingw32-gcc -DSQLITE_HAS_CODEC -I/cygdrive/c/OpenSSL-Win32/include -DSQLITE_OS_WIN=1 -I. -I./src -I./ext/rtree -D_HAVE_SQLITE_CONFIG_H -DBUILD_sqlite -DNDEBUG -DSQLITE_THREADSAFE=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 /cygdrive/c/OpenSSL-Win32/lib/libeay32.lib -DHAVE_READLINE=0 -o .libs/sqlite3.exe ./src/shell.c /usr/lib/gcc/i686-pc-mingw32/4.5.2/libgcc.a ./.libs/libsqlite3.a -lpthread -L/usr/local/lib
./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0xb04): undefined reference to `_EVP_get_cipherbyname'
./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0xb0d): undefined reference to `_OPENSSL_add_all_algorithms_noconf'
./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0xbeb): undefined reference to `_RAND_bytes'
./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x110f): undefined reference to `_EVP_get_cipherbyname'
./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x1123): undefined reference to `_EVP_CIPHER_key_length'
./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x113a): undefined reference to `_EVP_CIPHER_iv_length'
./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x1151): undefined reference to `_EVP_CIPHER_block_size'
./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x115f): undefined reference to `_EVP_sha1'
./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x1167): undefined reference to `_EVP_MD_size'
./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x1748): undefined reference to `_HMAC_CTX_init'
./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x174d): undefined reference to `_EVP_sha1'
./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x1784): undefined reference to `_HMAC_Init_ex'
./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x17a3): undefined reference to `_HMAC_Update'
./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x17c3): undefined reference to `_HMAC_Update'
./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x17e3): undefined reference to `_HMAC_Final'
./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x17f3): undefined reference to `_HMAC_CTX_cleanup'
./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x1a1e): undefined reference to `_EVP_CipherInit'
./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x1a34): undefined reference to `_EVP_CIPHER_CTX_set_padding'
./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x1a65): undefined reference to `_EVP_CipherInit'
./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x1a8f): undefined reference to `_EVP_CipherUpdate'
./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x1ab7): undefined reference to `_EVP_CipherFinal'
./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x1acb): undefined reference to `_EVP_CIPHER_CTX_cleanup'
./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x1c23): undefined reference to `_PKCS5_PBKDF2_HMAC_SHA1'
./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x1cf1): undefined reference to `_PKCS5_PBKDF2_HMAC_SHA1'
collect2: ld returned 1 exit status
Makefile:512: recipe for target `sqlite3.exe' failed
make: *** [sqlite3.exe] Error 1

I'm sure there is a more elegant way of solving this, but simply correcting the command which failed was sufficient for me (the linking order is the cause; any static library or object that depends on other library should be placed before it in the command line, so libeay32.lib should be placed after libsqlite3.a):

i686-pc-mingw32-gcc -DSQLITE_HAS_CODEC -I/cygdrive/c/OpenSSL-Win32/include -DSQLITE_OS_WIN=1 -I. -I./src -I./ext/rtree -D_HAVE_SQLITE_CONFIG_H -DBUILD_sqlite -DNDEBUG -DSQLITE_THREADSAFE=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DHAVE_READLINE=0 -o .libs/sqlite3.exe ./src/shell.c /usr/lib/gcc/i686-pc-mingw32/4.5.2/libgcc.a ./.libs/libsqlite3.a -lpthread -L/usr/local/lib /cygdrive/c/OpenSSL-Win32/lib/libeay32.lib

You should find the static library in sqlcipher_sources.lib directory, together with the sqlite3 executable.

Building a project linking to libsqlcipher.a

When building a project using the libsqlcipher, I had to link all the necessary libraries in the correct order:
  1. libeay32.lib
  2. libsqlite3.a
  3. libgcc.a
For example, in a Qt project I added this to link to the library:

win32 {
message("Compiling for Windows!")
LIBS += \
    $$_PRO_FILE_PWD_/os_specific_windows/3rdparty/lib/libeay32.lib \
    $$_PRO_FILE_PWD_/os_specific_windows/3rdparty/lib/libsqlite3.a \
    $$_PRO_FILE_PWD_/os_specific_windows/3rdparty/lib/libgcc.a

INCLUDEPATH += 3rdparty/include
}

Windows 7 64bit

After being asked, out of curiosity, I also tried to compile for Windows 7 64bit, and I followed the exact same procedure (I just downloaded and installed the 64bit version of all the libs and cygwin packages). The error during make is:

libtool: link: x86_64-w64-mingw32-gcc -shared .libs/sqlite3.o /usr/lib/gcc/x86_64-w64-mingw32/4.5.3/libgcc.a -lpthread -o .libs/cygsqlite3-0.dll -Wl,--enable-auto-image-base -Xlinker --out-implib -Xlinker .libs/libsqlite3.dll.a
Creating library file: .libs/libsqlite3.dll.a .libs/sqlite3.o:sqlite3.c:(.text+0xc73): undefined reference to `EVP_get_cipherbyname'
.libs/sqlite3.o:sqlite3.c:(.text+0xc7d): undefined reference to `OPENSSL_add_all_algorithms_noconf'
.libs/sqlite3.o:sqlite3.c:(.text+0xd7f): undefined reference to `RAND_bytes'
.libs/sqlite3.o:sqlite3.c:(.text+0x133a): undefined reference to `EVP_get_cipherbyname'
.libs/sqlite3.o:sqlite3.c:(.text+0x1352): undefined reference to `EVP_CIPHER_key_length'
.libs/sqlite3.o:sqlite3.c:(.text+0x136c): undefined reference to `EVP_CIPHER_iv_length'
.libs/sqlite3.o:sqlite3.c:(.text+0x1386): undefined reference to `EVP_CIPHER_block_size'
.libs/sqlite3.o:sqlite3.c:(.text+0x1395): undefined reference to `EVP_sha1'
.libs/sqlite3.o:sqlite3.c:(.text+0x139d): undefined reference to `EVP_MD_size'
.libs/sqlite3.o:sqlite3.c:(.text+0x1a37): undefined reference to `HMAC_CTX_init'
.libs/sqlite3.o:sqlite3.c:(.text+0x1a3c): undefined reference to `EVP_sha1'
.libs/sqlite3.o:sqlite3.c:(.text+0x1a76): undefined reference to `HMAC_Init_ex'
.libs/sqlite3.o:sqlite3.c:(.text+0x1a96): undefined reference to `HMAC_Update'
.libs/sqlite3.o:sqlite3.c:(.text+0x1ab3): undefined reference to `HMAC_Update'
.libs/sqlite3.o:sqlite3.c:(.text+0x1ad0): undefined reference to `HMAC_Final'
.libs/sqlite3.o:sqlite3.c:(.text+0x1ae2): undefined reference to `HMAC_CTX_cleanup'
.libs/sqlite3.o:sqlite3.c:(.text+0x1d38): undefined reference to `EVP_CipherInit'
.libs/sqlite3.o:sqlite3.c:(.text+0x1d4d): undefined reference to `EVP_CIPHER_CTX_set_padding'
.libs/sqlite3.o:sqlite3.c:(.text+0x1d7b): undefined reference to `EVP_CipherInit'
.libs/sqlite3.o:sqlite3.c:(.text+0x1da4): undefined reference to `EVP_CipherUpdate'
.libs/sqlite3.o:sqlite3.c:(.text+0x1dce): undefined reference to `EVP_CipherFinal'
.libs/sqlite3.o:sqlite3.c:(.text+0x1de4): undefined reference to `EVP_CIPHER_CTX_cleanup'
.libs/sqlite3.o:sqlite3.c:(.text+0x1f50): undefined reference to `PKCS5_PBKDF2_HMAC_SHA1'
.libs/sqlite3.o:sqlite3.c:(.text+0x2025): undefined reference to `PKCS5_PBKDF2_HMAC_SHA1'
/usr/lib/gcc/x86_64-w64-mingw32/4.5.3/../../../../x86_64-w64-mingw32/bin/ld: .libs/sqlite3.o: bad reloc address 0x1c0 in section `.data'
collect2: ld returned 1 exit status
Makefile:501: recipe for target `libsqlite3.la' failed
make: *** [libsqlite3.la] Error 1


So it seems that also the library now is failing to compile: maybe something has changed in some tool or in the Makefile, I don't know.
Luckily, sqlite3 uses amalgamation; it is therefore possible to compile manually quite simply. I built the library this way:

x86_64-w64-mingw32-ar cru .libs/libsqlite3.a /usr/lib/gcc/x86_64-w64-mingw32/4.5.3/libgcc.a sqlite3.o
x86_64-w64-mingw32-ranlib .libs/libsqlite3.a


since the object file sqlite3.o was already compiled by make, and the sqlcipher executable simply like this:

x86_64-w64-mingw32-gcc -DSQLITE_HAS_CODEC -I/cygdrive/c/OpenSSL-Win64/include -DSQLITE_OS_WIN=1 -I. -I./src -I./ext/rtree -D_HAVE_SQLITE_CONFIG_H -DBUILD_sqlite -DNDEBUG -DSQLITE_THREADSAFE=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DHAVE_READLINE=0 -o .libs/sqlite3.exe ./src/shell.c /usr/lib/gcc/x86_64-w64-mingw32/4.5.3/libgcc.a .libs/libsqlite3.a /cygdrive/c/OpenSSL-Win64/lib/libeay32.lib

I tried to create a simple encrypted database and seemed to work.
Hope this helps! 

33 comments:

  1. hi,

    ./configure --disable-tcl CFLAGS="-DSQLITE_HAS_CODEC -I/include" LDFLAGS="/lib/libeay32.lib /usr/lib/gcc/i686-pc-mingw32/4.5.2/libgcc.a"

    i didn't find "/usr/lib/gcc/i686-pc-mingw32/4.5.2/libgcc.a" file. what may be the reason ??

    incomplete cygwin installation ??

    ReplyDelete
  2. Did you install the packages I listed? Also, is 4.5.2 the version you installed?

    ReplyDelete
  3. Hi, i got the similar error as you mentioned about sqlite3.exe

    I them ran another command i got following error:
    ./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x1ab7): undefined reference to `_EVP_CipherFinal'
    ./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x1acb): undefined reference to `_EVP_CIPHER_CTX_cleanup'
    ./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x1c23): undefined reference to `_PKCS5_PBKDF2_HMAC_SHA1'
    ./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x1cf1): undefined reference to `_PKCS5_PBKDF2_HMAC_SHA1'
    collect2: ld returned 1 exit status


    can you help me out ??

    ReplyDelete
  4. I also checked the Makefile, I didn't found "libsqlite3.a" anywhere in it

    ReplyDelete
  5. Show the command line that caused the error.

    ReplyDelete
  6. hi Luca,

    About:
    i686-pc-mingw32-gcc -DSQLITE_HAS_CODEC -I/cygdrive/c/OpenSSL-Win32/include -DSQLITE_OS_WIN=1 -I. -I./src -I./ext/rtree -D_HAVE_SQLITE_CONFIG_H -DBUILD_sqlite -DNDEBUG -DSQLITE_THREADSAFE=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DHAVE_READLINE=0 -o .libs/sqlite3.exe ./src/shell.c /usr/lib/gcc/i686-pc-mingw32/4.5.2/libgcc.a ./.libs/libsqlite3.a -lpthread -L/usr/local/lib /cygdrive/c/OpenSSL-Win32/lib/libeay32.lib

    should i change it in Makefile ??

    i have following code in Makefile:

    # libtool compile/link/install
    LTCOMPILE = $(LIBTOOL) --mode=compile --tag=CC $(TCC) $(LTCOMPILE_EXTRAS)
    LTLINK = $(LIBTOOL) --mode=link $(TCC) $(LTCOMPILE_EXTRAS) /cygdrive/c/OpenSSL-Win64/lib/libeay32.lib /usr/lib/gcc/i686-pc-mingw32/4.5.2/libgcc.a $(LTLINK_EXTRAS)
    LTINSTALL = $(LIBTOOL) --mode=install $(INSTALL)

    ReplyDelete
  7. Might be the same issue. Yes, I modified the makefile.

    ReplyDelete
  8. can I have your modified makefile or know changes ?

    ReplyDelete
  9. I don't think I have it anymore, and also you might be using a different SQLCipher version. The line of least resistance might be to simply correct the compile line that is failing. For instance, this is what I just got:

    $ i686-pc-mingw32-gcc -DSQLITE_HAS_CODEC -I/cygdrive/c/OpenSSL-Win32/include -DSQLITE_OS_WIN=1 -I. -I./src -I./ext/rtree -D_HAVE_SQLITE_CONFIG_H -DBUILD_sqlite -DNDEBUG -DSQLITE_THREADSAFE=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 /cygdrive/c/OpenSSL-Win32/lib/libeay32.lib -DHAVE_READLINE=0 -o .libs/sqlite3.exe ./src/shell.c /usr/lib/gcc/i686-pc-mingw32/4.5.2/libgcc.a ./.libs/libsqlite3.a -lpthread -L/usr/local/lib
    ./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0xb04): undefined reference to `_EVP_get_cipherbyname'
    ./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0xb0d): undefined reference to `_OPENSSL_add_all_algorithms_noconf'
    ./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0xbeb): undefined reference to `_RAND_bytes'
    ./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x110f): undefined reference to `_EVP_get_cipherbyname'
    ./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x1123): undefined reference to `_EVP_CIPHER_key_length'
    ./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x113a): undefined reference to `_EVP_CIPHER_iv_length'
    ./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x1151): undefined reference to `_EVP_CIPHER_block_size'
    ./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x115f): undefined reference to `_EVP_sha1'
    ./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x1167): undefined reference to `_EVP_MD_size'
    ./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x1748): undefined reference to `_HMAC_CTX_init'
    ./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x174d): undefined reference to `_EVP_sha1'
    ./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x1784): undefined reference to `_HMAC_Init_ex'
    ./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x17a3): undefined reference to `_HMAC_Update'
    ./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x17c3): undefined reference to `_HMAC_Update'
    ./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x17e3): undefined reference to `_HMAC_Final'
    ./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x17f3): undefined reference to `_HMAC_CTX_cleanup'
    ./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x1a1e): undefined reference to `_EVP_CipherInit'
    ./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x1a34): undefined reference to `_EVP_CIPHER_CTX_set_padding'
    ./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x1a65): undefined reference to `_EVP_CipherInit'
    ./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x1a8f): undefined reference to `_EVP_CipherUpdate'
    ./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x1ab7): undefined reference to `_EVP_CipherFinal'
    ./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x1acb): undefined reference to `_EVP_CIPHER_CTX_cleanup'
    ./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x1c23): undefined reference to `_PKCS5_PBKDF2_HMAC_SHA1'
    ./.libs/libsqlite3.a(sqlite3.o):sqlite3.c:(.text+0x1cf1): undefined reference to `_PKCS5_PBKDF2_HMAC_SHA1'
    collect2: ld returned 1 exit status

    I changed to:

    $ i686-pc-mingw32-gcc -DSQLITE_HAS_CODEC -I/cygdrive/c/OpenSSL-Win32/include -DSQLITE_OS_WIN=1 -I. -I./src -I./ext/rtree -D_HAVE_SQLITE_CONFIG_H -DBUILD_sqlite -DNDEBUG -DSQLITE_THREADSAFE=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DHAVE_READLINE=0 -o .libs/sqlite3.exe ./src/shell.c /usr/lib/gcc/i686-pc-mingw32/4.5.2/libgcc.a ./.libs/libsqlite3.a -lpthread -L/usr/local/lib /cygdrive/c/OpenSSL-Win32/lib/libeay32.lib

    and I got my sqlite3 executable.

    ReplyDelete
  10. I tried both the commands and still got "collect2: ld returned 1 exit status" error

    Which sqlcipher version did you compile ??

    ReplyDelete
  11. I tried to download the latest version from github (might also be the same I already compiled), followed the steps in the procedure and I got both the static library and the executable. Check again your procedure, I don't know what might be stopping you, sorry.

    ReplyDelete
  12. Thanks Luca,

    the step is working for 32 bit windows, but i am trying to build sqlcipher for 64 bit windows and it is not working for 64 bit windows

    ReplyDelete
  13. Hi Luca, did you try in 64 bit windows ??

    ReplyDelete
  14. I'm sorry, but I don't have such a system available at the moment. If I found one, I suppose it might be interesting to try, but I don't know where to find it, sorry.

    ReplyDelete
  15. I brought up a 64bit environment and compiled SQLCipher for Windows 7 64bit. I reported some notes if you still need it.

    ReplyDelete
    Replies
    1. Hi Luca,

      I tried compiling SQLCipher in Windows 7, I also got similar error as you mentioned in the unresolved symbol. But I am not sure where to change the libeay32.lib at the end. Because in my makefile I do not see such a line. Can you please help.

      I did make and got the error as follows.

      $ make
      toEVP_get_cipherbyname'
      ./.libs/libsqlcipher.a(sqlite3.o):sqlite3.c:(.text+0x3e30): undefined reference
      to OPENSSL_add_all_algorithms_noconf'
      ./.libs/libsqlcipher.a(sqlite3.o):sqlite3.c:(.text+0x3eb0): undefined reference
      toEVP_cleanup'
      ./.libs/libsqlcipher.a(sqlite3.o):sqlite3.c:(.text+0x3f18): undefined reference
      to RAND_bytes'
      ./.libs/libsqlcipher.a(sqlite3.o):sqlite3.c:(.text+0x3f4b): undefined reference
      toHMAC_CTX_init'
      ./.libs/libsqlcipher.a(sqlite3.o):sqlite3.c:(.text+0x3f50): undefined reference
      to EVP_sha1'
      ./.libs/libsqlcipher.a(sqlite3.o):sqlite3.c:(.text+0x3f78): undefined reference
      toHMAC_Init_ex'
      ./.libs/libsqlcipher.a(sqlite3.o):sqlite3.c:(.text+0x3f94): undefined reference
      to HMAC_Update'
      ./.libs/libsqlcipher.a(sqlite3.o):sqlite3.c:(.text+0x3fb0): undefined reference
      toHMAC_Update'
      ./.libs/libsqlcipher.a(sqlite3.o):sqlite3.c:(.text+0x3fcf): undefined reference
      to HMAC_Final'
      ./.libs/libsqlcipher.a(sqlite3.o):sqlite3.c:(.text+0x3fdd): undefined reference
      toHMAC_CTX_cleanup'
      ./.libs/libsqlcipher.a(sqlite3.o):sqlite3.c:(.text+0x401f): undefined reference
      to PKCS5_PBKDF2_HMAC_SHA1'
      ./.libs/libsqlcipher.a(sqlite3.o):sqlite3.c:(.text+0x405d): undefined reference
      toEVP_CipherInit'
      ./.libs/libsqlcipher.a(sqlite3.o):sqlite3.c:(.text+0x4073): undefined reference
      to EVP_CIPHER_CTX_set_padding'
      ./.libs/libsqlcipher.a(sqlite3.o):sqlite3.c:(.text+0x409e): undefined reference
      toEVP_CipherInit'
      ./.libs/libsqlcipher.a(sqlite3.o):sqlite3.c:(.text+0x40cb): undefined reference
      to EVP_CipherUpdate'
      ./.libs/libsqlcipher.a(sqlite3.o):sqlite3.c:(.text+0x40fc): undefined reference
      toEVP_CipherFinal'
      ./.libs/libsqlcipher.a(sqlite3.o):sqlite3.c:(.text+0x4113): undefined reference
      to EVP_CIPHER_CTX_cleanup'
      ./.libs/libsqlcipher.a(sqlite3.o):sqlite3.c:(.text+0x4131): undefined reference
      toEVP_get_cipherbyname'
      ./.libs/libsqlcipher.a(sqlite3.o):sqlite3.c:(.text+0x4161): undefined reference
      to EVP_CIPHER_nid'
      ./.libs/libsqlcipher.a(sqlite3.o):sqlite3.c:(.text+0x4169): undefined reference
      toOBJ_nid2sn'
      ./.libs/libsqlcipher.a(sqlite3.o):sqlite3.c:(.text+0x417e): undefined reference
      to EVP_CIPHER_key_length'
      ./.libs/libsqlcipher.a(sqlite3.o):sqlite3.c:(.text+0x4193): undefined reference
      toEVP_CIPHER_iv_length'
      ./.libs/libsqlcipher.a(sqlite3.o):sqlite3.c:(.text+0x41a8): undefined reference
      to EVP_CIPHER_block_size'
      ./.libs/libsqlcipher.a(sqlite3.o):sqlite3.c:(.text+0x41b5): undefined reference
      toEVP_sha1'
      ./.libs/libsqlcipher.a(sqlite3.o):sqlite3.c:(.text+0x41bd): undefined reference
      to `EVP_MD_size'
      collect2.exe: error: ld returned 1 exit status
      make: *** [sqlcipher.exe] Error 1

      Could you help me what is going wrong and how to fix this?

      Delete
  16. yes Luca, that would be nice of you

    ReplyDelete
  17. Hi Luca, why have you deleted the post for compiling sqlcipher in windows ??

    ReplyDelete
  18. Oops! Sorry sorry my fault. Fixed it.

    ReplyDelete
  19. Hi Luca, can you provide me the dll built by you in 64 bit windows ?

    ReplyDelete
  20. Or, can you you provide me the command to generate the dll ?

    ReplyDelete
  21. Just compile as a shared library, something like x86_64-w64-mingw32-gcc -shared -Wl,-soname,libsqlite3.so -o libsqlite3.so.3.7.2 sqlite3.o /usr/lib/gcc/x86_64-w64-mingw32/4.5.3/libgcc.a /cygdrive/c/OpenSSL-Win64/libeay32.dll.

    ReplyDelete
  22. Thank-You-SO-Much !
    Worked exactly as described !

    ReplyDelete
  23. Hi, can you try to compile it for new sqlcipher source ?

    ReplyDelete
  24. Thanks for your library.

    I run your instructions from the command line of cygwin and I receive the followin messages:

    export CC=i686-pc-mingw32-gcc

    ((no message))

    cd sqlcipher_sources

    ((no message))

    $ ./configure --disable-tcl CFLAGS="-DSQLITE_HAS_CODEC -ID:\openssl_binaries/include" LDFLAGS="d:\openssl_binaries/lib/libeay32.lib /usr/lib/gcc/i686-pc-mingw32/4.5.2/libgcc.a"

    checking build system type... i686-pc-cygwin
    checking host system type... i686-pc-cygwin
    checking for gcc... i686-pc-mingw32-gcc
    checking whether the C compiler works... no
    configure: error: in `/cygdrive/d/sqlcipher_sources':
    configure: error: C compiler cannot create executables
    See `config.log' for more details

    $ i686-pc-mingw32-gcc -DSQLITE_HAS_CODEC -I/cygdrive/c/OpenSSL-Win32/include -DSQLITE_OS_WIN=1 -I. -I./src -I./src -I./ext/rtree -D_HAVE_SQLITE_CONFIG_H -DBUILD_sqlite -DNDEBUG -DSQLITE_THREADSAFE=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DHAVE_READLINE=0 -o .libs/sqlite3.exe ./src/shell.c /usr/lib/gcc/i686-pc-mingw32/4.5.2/libgcc.a ./.libs/libsqlite3.a -lpthread -L/usr/local/lib /cygdrive/c/OpenSSL-Win32/lib/libeay32.lib

    i686-pc-mingw32-gcc: error: /usr/lib/gcc/i686-pc-mingw32/4.5.2/libgcc.a: No such file or directory
    i686-pc-mingw32-gcc: error: ./.libs/libsqlite3.a: No such file or directory
    i686-pc-mingw32-gcc: error: /cygdrive/c/OpenSSL-Win32/lib/libeay32.lib: No such file or directory

    And inside d.\sqlcipher_sources I do not find the lib directory nor any library, nor any sqlite3 executable, as you mencioned.

    Can you tell me what has happend?

    Thanks.

    HERNAN CANO MARTINEZ
    Systems Analyst - Programmer
    Medellín, Antioquia, Colombia

    ReplyDelete
    Replies
    1. Hi.
      Any of you have done a .BAT for compile SQLCipher in Windows?
      Thanks.

      Thanks.

      HERNAN CANO MARTINEZ
      Systems Analyst - Programmer
      Medellín, Antioquia, Colombia

      Delete
  25. This comment has been removed by the author.

    ReplyDelete
  26. I ran the below command and got the error. Any help?

    Command : ./configure --disable-tcl CFLAGS="-DSQLITE_HAS_CODEC -I/cygdrive/c/OpenSSL-Win64/include" LDFLAGS="/cygdrive/c/OpenSSL-Win64/lib/libeay32.lib /usr/lib/gcc/i686-pc-mingw32/4.7.3/libgcc.a /cygdrive/c/OpenSSL-Win64/mingw64/lib/libcrypto.a"

    Error :
    checking for library containing pthread_create... -lpthread
    checking for crypto library to use... openssl
    checking for HMAC_Init_ex in -lcrypto... no
    configure: error: Library crypto not found. Install openssl!"

    ReplyDelete
  27. This comment has been removed by the author.

    ReplyDelete
  28. Hi Luca,

    thanks to your great preliminary work I've successfully built the static library. I'm trying to use these files in Qt Creator 3, adding LIBS and INCLUDEPATH for the appropriate platform in my .pro-file. I'm trying to load the QSQLCIPHER driver and open/create a unencrypted database, but the driver couldn't be loaded and the database creation fails.
    I'm going completely out of my mind...

    It is possible to post a .pro file and a way of the proper usage?

    Thanks in advance..!!

    ReplyDelete
  29. Can someone help me out? i ran the command for dynamic linking. and i got the makefile.. but i get the following error when i run 'make'

    $ make
    ./libtool --mode=link gcc -DSQLITE_HAS_CODEC -DSQLCIPHER_CRYPTO_OPENSSL -DSQLITE_OS_WIN=1 -I. -I./src -I./ext/rtree -D_HAVE_SQLITE_CONFIG_H -DBUILD_sqlite -DNDEBUG -I/usr/include -DSQLITE_THREADSAFE=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -lcrypto -DHAVE_READLINE=0 \
    -o sqlcipher.exe ./src/shell.c libsqlcipher.la \
    -lcrypto -rpath "/usr/local/lib"
    libtool: link: gcc -DSQLITE_HAS_CODEC -DSQLCIPHER_CRYPTO_OPENSSL -DSQLITE_OS_WIN=1 -I. -I./src -I./ext/rtree -D_HAVE_SQLITE_CONFIG_H -DBUILD_sqlite -DNDEBUG -I/usr/include -DSQLITE_THREADSAFE=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DHAVE_READLINE=0 -o sqlcipher.exe ./src/shell.c ./.libs/libsqlcipher.a -lcrypto -L/usr/local/lib
    /tmp/ccxpUJeT.o:shell.c:(.text+0x3178): undefined reference to `sqlite3_strglob'
    /tmp/ccxpUJeT.o:shell.c:(.text+0x3d42): undefined reference to `sqlite3_stricmp'
    /tmp/ccxpUJeT.o:shell.c:(.text+0x3e4b): undefined reference to `sqlite3_stricmp'
    /tmp/ccxpUJeT.o:shell.c:(.text+0x3e62): undefined reference to `sqlite3_stricmp'
    /tmp/ccxpUJeT.o:shell.c:(.text+0x3e80): undefined reference to `sqlite3_stricmp'
    /tmp/ccxpUJeT.o:shell.c:(.text+0x3e97): undefined reference to `sqlite3_stricmp'
    /tmp/ccxpUJeT.o:shell.c:(.text+0x617e): undefined reference to `sqlite3_strglob'
    ./.libs/libsqlcipher.a(sqlite3.o):sqlite3.c:(.text+0x410ec): undefined reference to `sqlite3CodecAttach'
    ./.libs/libsqlcipher.a(sqlite3.o):sqlite3.c:(.text+0x41112): undefined reference to `sqlite3CodecGetKey'
    ./.libs/libsqlcipher.a(sqlite3.o):sqlite3.c:(.text+0x41154): undefined reference to `sqlite3CodecAttach'
    ./.libs/libsqlcipher.a(sqlite3.o):sqlite3.c:(.text+0x555ee): undefined reference to `sqlite3_key'
    ./.libs/libsqlcipher.a(sqlite3.o):sqlite3.c:(.text+0x55637): undefined reference to `sqlite3_rekey'
    ./.libs/libsqlcipher.a(sqlite3.o):sqlite3.c:(.text+0x5577c): undefined reference to `sqlite3_key'
    ./.libs/libsqlcipher.a(sqlite3.o):sqlite3.c:(.text+0x557a9): undefined reference to `sqlite3_rekey'
    ./.libs/libsqlcipher.a(sqlite3.o):sqlite3.c:(.text+0x557f2): undefined reference to `sqlite3_activate_see'
    ./.libs/libsqlcipher.a(sqlite3.o):sqlite3.c:(.text+0x628ae): undefined reference to `sqlite3CodecGetKey'
    collect2: error: ld returned 1 exit status
    Makefile:542: recipe for target 'sqlcipher.exe' failed
    make: *** [sqlcipher.exe] Error 1

    ReplyDelete
  30. Link with compiled binaries better then a thousands words

    ReplyDelete