首先至sf.net上的wxcode工程去下载wxsqlite3的源代码,截止到笔者写这篇笔记,wxsqlite3的最新版本为3.0.2.
解压后,可看到目录结构如下:
drwx------+ 1 user group 0 Jan 25 13:04 build drwx------+ 1 user group 0 Dec 22 16:50 build29 -rwx------+ 1 user group 253977 Nov 23 23:31 configure -rwx------+ 1 user group 253977 Nov 23 23:31 configure28 -rwx------+ 1 user group 253443 Nov 23 23:31 configure29 drwx------+ 1 user group 0 Dec 22 16:50 dbadmin drwx------+ 1 user group 0 Dec 22 16:51 docs drwx------+ 1 user group 0 Dec 22 16:50 include drwx------+ 1 user group 0 Jan 24 22:46 lib -rwx------+ 1 user group 2550 Apr 12 2006 LICENCE.txt -rwx------+ 1 user group 18297 Nov 23 23:33 Makefile.in -rwx------+ 1 user group 18370 Nov 23 21:23 Makefile28.in -rwx------+ 1 user group 18297 Nov 23 21:23 Makefile29.in drwx------+ 1 user group 0 Dec 22 16:50 premake -rwx------+ 1 user group 3500 Jan 19 2012 premake4.lua -rwx------+ 1 user group 19363 Dec 22 16:45 Readme.txt drwx------+ 1 user group 0 Jan 25 13:04 samples drwx------+ 1 user group 0 Jan 25 12:21 sqlite3 drwx------+ 1 user group 0 Dec 22 16:50 src drwx------+ 1 user group 0 Dec 22 16:50 website -rwx------+ 1 user group 290 Dec 22 17:29 wxsqlite3.pc
由于笔者用的wxWidgets 2.8.12版,所以在build目录下可以找到各编译器的配置,官方直接提供有VS可用的编译配置。
这里笔者就尝试用codeblocks导入VS的工程:wxsqlite3_vc6_wxsqlite3.dsp
此时还需要修改一堆参数及路径,另一个办法是笔者这里采用的,详细如下:
拷贝一个在其他项目中用的LIB工程文件,cbp文件为XML格式,用文本工具NotePad++打开直接修改,也可以直接用笔者的工程文件,内容如下:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <CodeBlocks_project_file> <FileVersion major="1" minor="6" /> <Project> <Option title="wxsqlite3" /> <Option pch_mode="2" /> <Option compiler="gcc" /> <Build> <Target title="unicode-lib-rel"> <Option output="libwxsqlite3" prefix_auto="1" extension_auto="1" /> <Option working_dir="" /> <Option object_output="obj\" /> <Option type="2" /> <Option compiler="gcc" /> <Option createDefFile="1" /> <Compiler> <Add option="-O2" /> <Add option="-Wall" /> <Add option="-DWIN32" /> <Add option="-D_LIB" /> <Add option="-D_UNICODE" /> <Add option="-D__WXMSW__" /> <Add option="-DwxUSE_DYNAMIC_SQLITE3_LOAD=0" /> <Add option="-DWXSQLITE3_HAVE_METADATA=0" /> <Add option="-DWXSQLITE3_HAVE_CODEC=0" /> <Add option="-DWXSQLITE3_HAVE_LOAD_EXTENSION=0" /> <Add directory="$(wxWIN_PATH)\lib\gcc_lib\mswu" /> <Add directory="$(wxWIN_PATH)\include" /> <Add directory="$(wxWIN_PATH)\contrib\include" /> <Add directory="..\include" /> <Add directory="..\sqlite3\include" /> </Compiler> </Target> </Build> <Unit filename="..\include\wx\wxsqlite3.h" /> <Unit filename="..\include\wx\wxsqlite3def.h" /> <Unit filename="..\include\wx\wxsqlite3dyn.h" /> <Unit filename="..\include\wx\wxsqlite3opt.h" /> <Unit filename="..\src\wxsqlite3.cpp" /> <Extensions> <code_completion /> <debugger /> </Extensions> </Project> </CodeBlocks_project_file>
编译并链接后,在cbp所在目录生成libwxsqlite3.a文件,此时就可以在CB中调用了。
当然若是不想用sqlite的dll,还需要用CB重编译sqlite3.