SQLite 如何在Windows下编译?

SQLite 如何在Windows下编译?(发表时间: 2007-6-13 12:44:00)

【评论】 【打印】 【字体:  】 本文链接:http://blog.pfan.cn/lounger/26745.html 复制链接

分享到: 0

标签:C/C++ SQLite SQLite3 数据据库 DB 开源 跨平台 单机数据库 

SQLite -- 如何编译,使用。

译自SQLite Wiki,只提供Windows部分翻译,因为这近两天只是在用WX编程。以后补全:-)

限于本人水平,难免有误,还请批评!

MSVC与SQLite DLL

用下面的命令实现为MS Visual C++从sqlitedll.zip(http://www.sqlite.org/sqlitedll.zip)创建一个导入库:

LIB /DEF:sqlite.def

它将生成sqlite.lib和sqlite.exp文件。sqlite.lib能被用来链接到你你的程序中以使用SQLite DLL。

 

给初学者 用MS VC++ 5编译SQLite

这里提供给那象如我一样想一步一步重新编译SQLite。由于很久没有使用C语言了,如果有任何借误的地方,请指正:

  1. 安装MS VC++
  2. File | New | Projects: Choose Win32 DLL,并给你的工程名一名字。工程将被保存在它自己的文件夹下"\Program Files\DevStudio\MyProjects\"。仔细地确定名字,因为它将用来生成DLL
  3. 解压SQLite源文件到这个子文件夹中(注:我知道有两个版本的源代码。一个是通用的,例如,不针对特定的操作系统。而另一个源代码包特定说明,为MS VC++而准备的。选择后面一个)
  4. Project | Add to Project | Files,导入到你工程所在的文件夹,现在包含了SQLite源文件,然后选择所有已加入你工程的C文件(注:如果想从你工程中删除某一个文件,用鼠标选中它,然后按DEL键。没有这个操作的菜单项的快捷弹出菜单)
  5. 如果你没有用TCL(一个脚本语言),移除tclsqlite.c
  6. Build | Set Active Configuration, 并选中"My Project - Win32 Release"以便于我们可以产生一个不带调试信息的无格式的DLL
  7. 如果你想增加版本信息以便于可以在Windows浏览器中鼠标右键DLL信息时得到一个版本号,选择Project | Add to project ! New : Resource Script。一个纯文本角本res.rc被添加到你的工程中你可以编辑它以包含版本信息(我还没有找到一个如何让版本自动增加的办法。)由于这个嵌入的版本信息是独立于sqlite_libversion()返回值的,因此,不要担心前者是四位数而后者用三位数字
  8. Build | Rebuild All。你将看到许多警告,但只是它正常运行,现在你将在你的我程的Release/子目录得到一个DLL
Visual studio 2012 下 sqlite3的工程文件,生成32或64位的sqlite3库 This page explains how to compile SQLite with Microsoft Visual Studio.NET (aka VS.NET). Download Download and unzip the file sqlite_source.zip (or sqlite-amalgamation-x_x_x_x.zip). Do not use the .tar.gz files because they have not been pre-processed for use with Windows. Create a starter DLL project File > New > Project. Under Project Types, select Visual C++ Projects and then Win32. Choose the project template "Win32 Project". Give the project a name and click OK. When the "Win32 Application Wizard" appears, choose Application Settings. set the Application Type to DLL and check the box that says "Empty project". Click Finish. You now have a blank DLL project. Add the SQLite files to the project Project > Add Existing Item. Add all the .c and .h files that you unzipped, except for: tclsqlite.c and shell.c. Note: You may add tclsqlite.c and shell.c, but then you have to define the preprocessor-symbol NO_TCL. Click Project -> Properties, navigate to the C/C++-folder and choose "Preprocessor". In the field that says "Preprocessor definitions" add NO_TCL to the existing string, separated by a semicolon. Under "Code Generation" for "Runtime Library" make sure to pick static linking. /MTd (release) or /MTd (debug) Make a .DEF file A .def file should be placed in the project directory. Get the def file by downloading the zipped sqlite DLL file under the "Precompiled Binaries For Windows" in the download page. Add the sqlite[3].def file to the project. Under Project > Properties navigate to the Linker folder and choose "Input". In the field that says "Module Definition File" type sqlite[3].def. NOTE: You have to do this twice, once for the Debug configuration and once for the Release configuration. Compile! The next 3 steps maybe be required by some. I was able to build the DLL and produce a .lib file only following the above 12 steps. for VS 2005. In order to build the lib file so that an application can link against the sqlite[3].dll you will need to add a step to the post-build event. Right click on Project, select Properties, expand Build Events and type "LIB /DEF:\sqlite[3].def" into the Command line field, both for debug and release configurations, where is the location to the file sqlite[3].def. To compile 3.3.7(this may apply to other versions too), I had to do this extra step: Add the project directory to the include path, here's how to do it in details: Under Project > Properties navigate to the C/C++ folder and choose "General", In the field "Additional Include Directories" type "."(a single dot, which is the current directory) Repeat for each configuration (debug/release/Win32/x64). To compile 3.6.14.1 (maybe others too), I also had to: Go to Project > Properties. Open the C/C++ then Preprocessor folder. Add "SQLITE_ENABLE_COLUMN_METADATA" to the list of preprocessor definitions. Repeat for each configuration (debug/release/Win32/x64). How to make the SQLITE.EXE command-line utility There are some slight changes if you wanted to build the sqlite.exe command-line utility, instead of the DLL. To do that, when you're creating the project and you get to the "Win32 Application Wizard", choose "Console Application" instead of "DLL". Then, when you are adding files to the project, also add shell.c. Finally, don't include the .DEF file. The sqllite def for version 2 is. EXPORTS sqlite_open sqlite_close sqlite_exec sqlite_last_insert_rowid sqlite_error_string sqlite_interrupt sqlite_complete sqlite_busy_handler sqlite_busy_timeout sqlite_get_table sqlite_free_table sqlite_mprintf sqlite_vmprintf sqlite_exec_printf sqlite_exec_vprintf sqlite_get_table_printf sqlite_get_table_vprintf sqlite_freemem sqlite_libversion sqlite_libencoding sqlite_changes sqlite_create_function sqlite_create_aggregate sqlite_function_type sqlite_user_data sqlite_aggregate_context sqlite_aggregate_count sqlite_set_result_string sqlite_set_result_int sqlite_set_result_double sqlite_set_result_error sqliteMalloc sqliteFree sqliteRealloc sqlite_set_authorizer sqlite_trace sqlite_compile sqlite_step sqlite_finalize sqlite_progress_handler sqlite_reset sqlite_last_statement_changes
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值