SQLCipher ported to Harbour (Windows - MingW)

263 views
Skip to first unread message

rathinagiri subbiah

unread,
Feb 9, 2012, 2:40:12 AM2/9/12
to Harbour Users
I am happy that I could port SQLCipher to Harbour (Windows)
successfully:

Here are the steps I have followed to port it to Harbour: (My System
is Vista Ultimate, HMG 3.0.40)

If you do not want to know about the build procedure and straightaway
use SQLCipher you can go to step 12.

1. Downloaded SQLCipher Source code from here.
https://github.com/sqlcipher/sqlcipher/tarball/v2.0.3 This version is
based on SQLite version 3.7.9) in c:\sqlcipher

2. Downloaded and installed MingW + Msys latest version from
http://sourceforge.net/projects/mingw/files/latest/download?source=files
in c:\mingw

3. Downloaded and installed ActiveState TCL from
http://www.activestate.com/activetcl/downloads in c:\tcl
TCL is not required for SQLite as such. But MingW & MSys requires TCL
to generate some c codes. It requires AWK too. But MingW installation
includes AWK. So, there is no problem once you install Mingw + MSys.

4. Downloaded and installed OpenSSL from http://www.slproweb.com/products/Win32OpenSSL.html
in c:\openssl

5. Copied c:\openssl\include\openssl folder to c:\mingw\include
\openssl

6. Copied c:\openssl\lib\mingw\libeay32.a to c:\mingw\msys\1.0 (This
is not required, but I have done for easy path)

7. Opened Command prompt. Set path to mingw and msys using the
following commands, changed directory to SQLCipher and opened shell:
[code]
c:\>path=%path%;c:\mingw\bin;c:\mingw\msys\1.0\bin
c:\>cd sqlcipher
c:\sqlcipher>sh
[code]

7. Run configure script as mentioned in SQLCipher site as below in the
shell prompt as instructed in SQLCipher.net:
[code]
./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC"
LDFLAGS="libeay32.a"
[/code]

8. Once the configuration is over, type make
[/code]
make
[/code]

This command would create many files including amalgamated single
sqlite3.c and sqlite3.h

The make command gave many errors, I could not trace out but we need
not worry about this as we require only sqlite3.c and sqlite3.h as
above.

9. Created a directory sqlcipher inside Harbour folder. Copied
sqlite3.c and sqlite3.h to this folder. Copied c:\openssl\lib
\libeay32.a to c:\hmg.3.0.40\lib folder for having openssl at the time
of application building.

10. Created the following hbc and hbp files:

sqlcipher.hbp file.
[code]
#
# $Id: sqlite3.hbp 16257 2011-02-09 12:47:35Z vszakats $
#

-stop{hbdyn}

-stop{poccarm}
# NOTE: old msvcarm can't cope with some PP directives. [vszakats]
-stop{msvcarm&HB_COMP_VER!='1200'&HB_COMP_VER!='1300'&HB_COMP_VER!
='1310')}
# NOTE: dos based watcom runs out of memory. [vszakats]
-stop{HB_HOST_PLAT='dos'&watcom}
# NOTE: disable *nix builds on non-*nix platforms; [vszakats]
# except for cygwin-on-win
-stop{!(HB_HOST_PLAT='win'&cygwin)&HB_HOST_PLAT_UNIX=''&unix}

-hblib
-inc

-o${hb_targetname}

-warn=low
-cpp=no

-cflag=-DSQLITE_HAS_CODEC
-cflag=-DSQLITE_OMIT_DEPRECATED
-cflag=-DSQLITE_ENABLE_COLUMN_METADATA
-cflag=-D_WIN32_WCE{wce}
# DJGPP and OpenWatcom in DOS aren't correctly recognized by SQLite,
# so we're forcing the next best available option. This will cause
missing
# externals though. [vszakats]
-cflag=-DSQLITE_OS_OTHER{dos}
# Watcom Linux builds cannot use system header files
-cflag=-DSQLITE_OS_OTHER{linux&watcom}

-cflag=-DSQLITE_THREADSAFE=0{minix}
-cflag=-DSQLITE_OMIT_LOAD_EXTENSION=1{minix}

sqlite3.c

[/code]

sqlcipher.hbc
[code]
#
# $Id: sqlite3.hbc 16215 2011-02-05 15:53:17Z vszakats $
#

libs=${hb_name}

cflags=-DSQLITE_OMIT_LOAD_EXTENSION=1{minix}
[/code]

11. Created buildlib.bat as below and run in the command prompt:
[code]
SET HMGPATH=\hmg.3.0.40

SET PATH=%HMGPATH%\harbour\bin;%HMGPATH%\mingw\bin;%PATH%

hbmk2 sqlcipher.hbp -i%hmgpath%\include
[/code]

File libsqlcipher.a is created by the above step. Copied this file to
c:\hmg.3.0.40\lib folder.

12. Created a sample hmg application to find out whether everything is
fine:
sample.prg
[code]
#include <hmg.ch>

Function Main
local oDB := nil
local cKey := 'password123'
local cFile := 'sample.sqlite'
local aTable := {}

if file( cFile )
oDB := connect2db( 'sample.sqlite', .f. )
if oDB == Nil
msgstop( 'Database File can not be connected' )
else
msginfo( iif( miscsql( oDB, 'pragma key = ' +
c2sql( cKey ) ), 'Encryption Key is set', 'Encryption key can not be
set' ) )
aTable := sql( oDB, 'select name, city from master' )
if len( aTable ) > 0
msginfo( 'Name:' + aTable[ 1, 1 ] + ' City:' + aTable[ 1,
2 ] )
endif
endif
else
oDB := connect2db( 'sample.sqlite', .t. )
if oDB == Nil
msgstop( 'Database File can not be connected' )
else
msginfo( iif( miscsql( oDB, 'pragma key = ' +
c2sql( cKey ) ), 'Encryption Key is set', 'Encryption key can not be
set!' ) )
msginfo( iif( miscsql( oDB, 'create table master (name,
city)' ), 'Master table is created successfully!', 'Table can not be
created!' ) )
msginfo( iif( miscsql( oDB, 'insert into master ( name,
city ) values ( ' + c2sql( 'Name1' ) + ', ' + c2sql( 'City1' ) +
' )' ), 'Sample Data updated', 'sample data can not be updated!' ) )
endif
endif
Return nil
[/code]

13. Compiled using the following HMG-IDE configuration:
[code]
inc=yes
head=native
libs=hmgsqlite
libs=sqlcipher
libs=eay32
[/code]

14. Note: All our applications created using the above libsqlcipher.a
library requires libeay32.dll at the runtime. It can be kept in the
same directory as application file or can be kept at c:\windows
\system32 folder too.

You can download sqlcipher compiled library from here (http://
www.rathinagiri.in/sqlcipher.zip). Kindly test with your applications
and give your feedback.

Enjoy HMGing!

Gmail

unread,
Feb 9, 2012, 6:01:55 AM2/9/12
to harbou...@googlegroups.com
Hello Rathinagiri,

Thanks for sharing such information.
I was pretty sure you would suceed porting SQLCipher to Harbour and
MingW.
I will try your steps.
Regards,

Qatan

> --
> You received this message because you are subscribed to the Google
> Groups "Harbour Users" group.
> Unsubscribe: harbour-user...@googlegroups.com
> Web: http://groups.google.com/group/harbour-users
>

Gmail

unread,
Feb 9, 2012, 8:22:35 AM2/9/12
to harbou...@googlegroups.com
Hello Rathinagiri,

Is there any way to avoid having an external DLL?
I mean, just the EXE file? How to do that? Do you know?
I do not like external files, if possible of course.
Thanks for your help.
Regards,

Qatan

----- Original Message -----
From: "rathinagiri subbiah" <srathi...@gmail.com>
To: "Harbour Users" <harbou...@googlegroups.com>
Sent: Thursday, February 09, 2012 05:40
Subject: [harbour-users] SQLCipher ported to Harbour (Windows - MingW)

hari gaire

unread,
Nov 23, 2012, 12:50:32 AM11/23/12
to harbou...@googlegroups.com
Hi, as mentioned in step 6, i din't find  "c:\openssl\lib\mingw\libeay32.a" file.
what may be the reason
Reply all
Reply to author
Forward
0 new messages