SQLite安装教程

1 下载软件 html

官网 http://www.sqlite.org/download.html
(1) 下载如下 3 *.zip 文件
Source Code:
sqlite-amalgamation-3090200.zip // C source code
Precompiled Binaries for Windows:
sqlite-shell-win32-x86-3090200.zip // The command-line shell program
sqlite-dll-win32-x86-3090200.zip // 32-bit DLL (x86) for SQLite
(2) 解压缩到同一个文件夹下
C 语言开发须要这几个文件: sqlite3.def sqlite3.dll sqlite3.h
 
使用第三方库须要 xxx.dll, xxx.lib 和 xxx.h 三种文件。为此,须要将 sqlite3.def 转换成 sqlite3.lib ,以便咱们使用。
(1) sqlite3.def sqlite3.dll 拷贝到 c:\ 根目录下
(2) Windows 系统菜单里,找到 "Visual Studio 2017 的开发人员 命令提示符 " ,以管理员身份单击运行打开
命令行窗口。(或者,从 VS 的菜单“工具 |Visual Studio 2017 Command Prompt
也能够打开此窗口)。

按照以下输入命令:sql

如今,咱们已经获得了 sqlite3.dll , sqlite3.lib sqlite3.h ,就能够正常的调用 sqlite3
中的 API 函数了。(注:再也不须要 sqlite.def 这个文件)
示例代码 :
#include <stdio.h>

/* SQLite3 Support */
#include "sqlite3.h"
#pragma comment(lib, "sqlite3.lib")

int main()
{
	// 建立数据库
	sqlite3 *db = NULL;
	int rc = sqlite3_open("example.db", &db);
	if( rc != 0)
	{
		printf("error!\n");
		return -1;
	}

	sqlite3_close(db);
	return 0;
}
备注:编译出现LINK : warning LNK4068: 未指定 /MACHINE;默认设置为 X86 
        sqlite LNK4272    库计算机类型“x86”与目标计算机类型“x64”冲突
等相似错误是由于 默认设置为 X86 若是是64位操做系统须要将以前的C:\>lib /DEF:sqlite3.def命令改成C:\>lib /DEF:sqlite3.def /MACHINE:X64产生新的sqlite3.lib