由于项目需要,需要编译SQLCipher 以便保持ios android windows统一
1.安装vs2013,其他的我没有测试过
2.安装 Activestate Perl, 下载地址http://www.activestate.com/activeperl
3.下载并编译openssl,我用的版本是openssl-1.0.1p.tar.gz
如何编译这个我在我的另一篇教程里面提到了,参考http://blog.csdn.net/herorazor/article/details/47610445
4.安装Mingw 网址:http://sourceforge.net/projects/mingw/files/
下载那个名字叫Download mingw-get-setup.exe (86.5 kB)的东西
安装以后如图
5.安装gcc msys mingw等相关工具,具体的我也是自己差什么安装什么,官网说的不太清楚
反正gcc msys tclsh相关的都安装.不然后面编译会报错!
比如我当时没下tclsh相关的就报tclsh command not found,
gcc没装就报checking for gcc... no
所以能选的都选上吧。。我这个上面折腾很久。。
安装方法,例如msys,
(1)选择左侧MSYS Base System,
(2)右侧msys-base 点击右键选择Mark for installation
(3)然后点击软件菜单里面里面的installation中的Apply Changes,
然后弹出一个对话框,点击Apply,就开始安装
6.安装完成以后 ,会在c盘生成C:\MinGW等文件夹
7.准备开始编译了,先设置环境变量,我的变量参考C:\Perl\bin;C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin;C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE;C:\MinGW\msys\1.0\bin;c:\MinGW\bin
之前编译好的openssl 会在c盘生成文件,如下图,如何生成请参考的我上面给的连接地址
8.openssl 生成的ibeay32.lib libeay32.dll等全部拷贝一份在sqlcipher主目录下
运行C:\MinGW\msys\1.0\msys.bat,然后进入sqlcipher主目录下,
命令行cd D:\sqlcipher\sqlcipher-master
然后开始执行
./configure --with-crypto-lib=none --disable-tcl CFLAGS="-DSQLITE_HAS_CODEC -DSQLCIPHER_CRYPTO_OPENSSL -I/c/opensslbuild32/include /d/sqlcipher/sqlcipher-master/libeay32.dll -L/d/sqlcipher/sqlcipher-master/ -static-libgcc" LDFLAGS="-leay32"
这个不能复制粘贴很蛋疼,参数中的路径可以自己修改下
然后依次继续执行命令
make clean
make sqlite3.c
make
make dll
此时应该就会生成sqlite3.c文件了
9.然后就开始使用了,sqlite3.h sqlite3.c sqlite3ext.h ssleay32.dll ssleay32.lib libeay32.dll libeay32.lib 这几个文件拷贝到一个新建工程下面就开始使用了
vs工程里面添加如下宏定义
SQLITE_HAS_CODEC=1
CODEC_TYPE=CODEC_TYPE_AES128
SQLITE_CORE
THREADSAFE
SQLITE_SECURE_DELETE
SQLITE_SOUNDEX
SQLITE_ENABLE_COLUMN_METADATA
附带一个测试代码
// Test.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "sqlite3.h"
static int callback(void *NotUsed, int argc, char **argv, char **azColName) {
//feed this callback function to handle theresultset returned by the select statement
int i;
for (i = 0; i < argc; i++) { //loop over results
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL"); //gota love how human radable c is
}
printf("\n");
return 0;
} //end callback
int _tmain(int argc, _TCHAR* argv[])
{
sqlite3 *db;
if (sqlite3_open("test.db3", &db) == SQLITE_OK)
{
int n = sqlite3_key(db, "123", 3);
//sqlite3_rekey(db, "", 0);
/*printf("DB file is open\n");
if (sqlite3_exec(db, (const char*)"PRAGMA key ='password'", NULL, NULL, NULL) == SQLITE_OK){
printf("Accepted Key\n");
};*/
if (sqlite3_exec(db, (const char*)"CREATE TABLE StaffMember (sid varchar(256), name varchar(20),age varchar(20));", NULL, NULL, NULL) == SQLITE_OK) {
printf("Created Table\n");
};
/*if (sqlite3_exec(db, (const char*)"INSERT INTO testtable (id,name) values (0,'alice'), (1,'bob'), (2,'charlie');", NULL, NULL, NULL) == SQLITE_OK) {
printf("Gave it some data\n");
};
*/
if (sqlite3_exec(db, (const char*)"insert into StaffMember(sid, name, age) values('001', '草泥马', '17')", NULL, NULL, NULL) == SQLITE_OK)
{
printf("Sent Select\n");
}
if (sqlite3_exec(db, (const char*)"SELECT * FROM StaffMember;", callback, NULL, NULL) == SQLITE_OK) {
printf("Sent Select\n");
};
/*if (sqlite3_exec(db, (const char*)"delete from StaffMember where sid = '001'", NULL, NULL, NULL) == SQLITE_OK)
{
printf("Sent Select\n");
}*/
}
sqlite3_close(db); //close it up properly
return 0;
}
10.参考文献http://www.jerryrw.com/howtocompile.php