1.å¦ä½ç¼è¯SQLite-How To Compile SQLite
å¦ä½ç¼è¯SQLite-How To Compile SQLite
SQLiteæ¯ANSI-Cçæºä»£ç ãå¨ä½¿ç¨ä¹åå¿ é¡»è¦ç¼è¯ææºå¨ç ãè¿ç¯æç« æ¯ç¨äºåç§ç¼è¯SQLiteæ¹æ³çæåã
è¿ç¯æç« ä¸å å«ç¼è¯SQLiteçæ¯ä¸ªæ¥éª¤çåé¦ï¼é£æ ·å¯è½ä¼å°é¾å 为æ¯ç§å¼ååºæ¯é½ä¸åãæ以è¿ç¯æç« æè¿°åéè¿°äºç¼è¯Sqliteçååãå ¸åçç¼è¯å½ä»¤å·²ç»ä½ä¸ºä¾åæä¾äºï¼ä»¥ææåºç¨å¼åè è½å¤ä½¿ç¨è¿äºä¾åä½ä¸ºå®æä»ä»¬èªå·±å®å¶çç¼è¯è¿ç¨ççä¸ä¸ªæåãæ¢å¥è¯è¯´ï¼è¿ç¯æç« æä¾äºæ³æ³åè§è§£ï¼èä¸æ¯äº¤é¥åç解å³æ¹æ³ã
èåVSåç¬æºæ件
Sqliteæ¯ç±è¶ è¿ä¸ç¾ä¸ªcæºç æ件以åä¼å¤çç®å½ä¸çèæ¬æ建çãSqliteçå®ç°æ¯çº¯ç²¹çANSI-Cï¼ä½æ¯è®¸å¤Cè¯è¨æºä»£ç æ件æ¯ç±è¾ å©çCç¨åºçææè 转æ¢æ¥çï¼å¹¶ä¸AWKï¼SEDåTCLèæ¬ä¼èåå°å®æçsqliteåºä¸ã对Sqliteæ建éè¦çCç¨åºå转æ¢åå建Cè¯è¨æºç æ¯ä¸ä¸ªå¤æçè¿ç¨ã
为äºç®åè¿äºï¼sqliteä¹éè¿ä¸ä¸ªé¢æå çå并åçæºç æ件ï¼sqlite3.cãè¿ä¸ªå并æ件æ¯ä¸ä¸ªANSI-Cæºç å®ç°æ´ä¸ªSQLiteåºçå¯ä¸æ件ãå并åçæ件æ´å®¹æå¤çãææçä¸è¥¿é½å å«å¨è¿ä¸ä¸ªæ件éï¼æ以å¾å®¹æè¿å ¥ä¸ä¸ªæ´å¤§çCæè C++ç¨åºçæºç æ ãææç代ç çæå转æ¢æ¥éª¤é½å·²ç»å®ç°äºï¼å æ¤æ²¡æè¾ å©çCç¨åºéè¦å»é ç½®ååå¼ï¼ä¹æ²¡æèæ¬éè¦å»è¿è¡ã并ä¸ï¼å æ¤ææåé½å å«å¨ä¸ä¸ªç¿»è¯åå ï¼ç¼è¯å¨å¯ä»¥åæ´å¤é«çº§çä¼åä»èæå5%å°%çæ§è½ãå 为è¿äºåå ï¼èååçæºç æ件sqlite3.c对ææç¨åºæ¥è®²é½æ¯å¼å¾æ¨èçã
æ¨èææçåºç¨ç¨åºä½¿ç¨èåæ件ã
ç´æ¥ä»åç¬çæºç æ件ä¸æ建sqliteå½ç¶å¯ä»¥ï¼ä½æ¯å¹¶ä¸æ¨èã对ä¸äºç¹æ®çåºç¨ç¨åºï¼å¯è½éè¦ä¿®æ¹æ建ç¨åºå»å¤ç使ç¨é£äºä»ç½ç«ä¸ä¸è½½çé¢æ建çæºç æ件ä¸è½å®æçæ åµã对äºè¿äºæ åµï¼æ¨èæ建å使ç¨ä¸ä¸ªå®å¶è¿çå并æ件ãæ¢å¥è¯è¯´ï¼å³ä½¿ä¸ä¸ªå·¥ç¨éè¦ä»¥åç¬çæºç æ件æ建sqliteï¼ä»ç¶æ¨è使ç¨ä¸ä¸ªèååçæºç æ件ä½ä¸ºä¸ä¸ªä¸é´æ¥éª¤ã
ç¼è¯å½ä»¤è¡æ¥å£ï¼CLIï¼
æ建å½ä»¤è¡æ¥å£éè¦ä¸ä¸ªæºç æ件ï¼
sqlite3.c:Sqliteèåçæºç æ件
sqlite3.h:å¹é sqlite3.c以åå®ä¹sqliteçcè¯è¨æ¥å£ç头æ件
shell.c:å½ä»¤è¡æ¥å£ç¨åºæ¬èº«ãè¿ä¸ªcæºç æ件å å«ä¸ä¸ªmain()çä¾ç¨åæ¯è½®å¾ªç¯çç¨æ·è¾å ¥çæ示符并å°è¾å ¥ä¼ ç»sqliteæ°æ®åºå¼æç¨äºå¤çã
ææçä¸è¿°æºç çä¸ä¸ªæ件é½è¢«å å«å¨ä¸è½½é¡µé¢çamalgamation tarballä¸ã
为äºæ建CLIï¼ç®åçå°è¿ä¸ä¸ªæ件æ¾ç½®å¨ç¸åçç®å½ä¸ç¶åä¸èµ·ç¼è¯ä»ä»¬ãç¨MSVCï¼
cl shell.c sqlite3.c -Fesqlite3.exe
å¨unixç³»ç»ä¸ï¼æè å¨windowsä¸ç¨cygwinæè mingw+msysï¼å ¸åçå½ä»¤ä¼æäºåè¿æ ·ï¼
gcc shell.c sqlite3.c -lpthread -ldl
为äºSQLite线ç¨å®å ¨ï¼éè¦pthreadsåºãä½æ¯å 为CLIæ¯ä¸ä¸ªå线ç¨çï¼æ们å¯ä»¥æ示SQLiteæ建ä¸ä¸ªé线ç¨å®å ¨çåºå¹¶å æ¤æ¤ç»¿pthreadsåºï¼
gcc -DSQLITE_THREADSAFE=0 shell.c sqlite3.c -ldl
-ldlåºæ¯å¨æ¯æå¨æè£ è½½æ¶éè¦ï¼ä¾å¦sqlite3_load_extension() æ¥å£åload_extension()
SQL functionãå¦æè¿äºç¹æ§é½ä¸è¦æ±ï¼é£ä¹æ们ä¹å¯ä»¥ä½¿ç¨SQLITE_OMIT_LOAD_EXTENSIONç¼è¯æ¶é´é项忽ç¥ä»ä»¬ã
gcc -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION shell.c sqlite3.c
æ人å¯è½æ³è¦æä¾å ¶ä»çç¼è¯æ¶é´é项(compile-time options)ï¼ä¾å¦SQLITE_ENABLE_FTS3å»å ¨ææ¬æç´¢æè SQLITE_ENABLE_RTREEç¨äºR*æ æç´¢å¼ææ©å±ãèæ人å°æ£å¸¸æå®ä¸äºç¼è¯ä¼åå¼å ³ãï¼é¢ç¼è¯çCLIå¯ä»¥ä»éæ©sqliteç½ç«ä¸ä½¿ç¨â-Osâä¸è½½ä¸æ¥ï¼ææ æ°ç§å¯è½çåæ°å¨è¿éã
å ³é®ç¹å¨è¿éï¼æ建CLIéè¦ç¼è¯ä¸èµ·ä¸¤ä¸ªCè¯è¨æ件ãshell.cæ件å å«å ¥å£çå®ä¹åç¨æ·è¾å ¥çloopï¼èsqliteèåæ件sqlite3.cå å«å®æ´çsqliteåºçå®ç°ã
ç¼è¯TCLæ¥å£
sqliteçtclæ¥å£æ¯ä¸ä¸ªå°ç模å被添å å°ä¸è¬çèåæ件ä¸ãç»ææ¯ä¸ä¸ªæ°çèååçæºç æ件ï¼ç§°ä¹ä¸ºâtclsqlite3.câãè¿ä¸ªæºç æ件æ¯çæä¸ä¸ªå¯ä»¥ä½¿ç¨TCL
loadå½ä»¤å»å è½½å°ä¸ä¸ªæ åçtclshæè wishä¸ï¼æè éçsqliteæ建æåçæä¸ä¸ªåç¬å¯ä¸çtclshçå ±äº«åºæéè¦çãä¸ä¸ªtclçèåçå¯æ¬è¢«å å«å¨ä¸è½½é¡µçTEA
tarballä¸ä½ä¸ºä¸ä¸ªæ件ã
为äºçæä¸ä¸ªlinuxä¸çsqliteçTCL-loadableåº,web源码脱敏ä¸é¢çå½ä»¤éè¦æ»¡è¶³ï¼
gcc -o libtclsqlite3.so -shared tclsqlite3.c -lpthread -ldl -ltcl
ä¸å¹¸çæ¯æ建Mac OS X å Windowsçå ±äº«åºå¹¶ä¸æ¯å¦æ¤ç®åã对äºè¿äºå¹³å°æ好使ç¨å å«å¨TEA tarballä¸çconfigureèæ¬åmakefile.
为äºçæä¸ä¸ªåç¬çtclshï¼å¯ä»¥ç¨äºsqliteéæé¾æ¥ï¼ä½¿ç¨å¦ä¸çç¼è¯å¨è°ç¨ï¼
gcc -DTCLSH=1 tclsqlite3.c -ltcl -lpthread -ldl -lz -lm
è¿éçæå·§æ¯-DTCLSH=1é项ãsqliteçTCLæ¥å£æ¨¡åå å«ä¸ä¸ªmainçè¿ç¨ï¼ç¨äºåå§åä¸ä¸ªTCL解éå¨å¹¶å¨ä»¥-DTCLSH=1ç¼è¯åè¿å ¥å°ä¸ä¸ªå½ä»¤è¡loopãä¸è¿°å½ä»¤å¯ä»¥å·¥ä½å¨LinuxåMac
OS X,è½ç¶ææ¶å¯è½éè¦ä¾èµäºå¹³å°è°æ´åºé项以åç¼è¯çTCLçåªä¸ä¸ªçæ¬ã
æ建èåæ件
ä¸è½½é¡µæä¾çsqliteèåæ件ççæ¬å¯¹å¤§å¤æ°ç¨æ·æ¥è¯´æ¯è¶³å¤çãç¶èï¼ä¸äºå·¥ç¨å¯è½æ³è¦æè éè¦æ建ä»ä»¬èªå·±çèåæ件ãä¸ä¸ªå¸¸è§çæ建ä¸ä¸ªå®å¶çèåæ件ççç±æ¯ä¸ºäºä½¿ç¨ç¹å®çcompile-time optionsæ¥å®å¶sqliteåºãåæ³sqliteèåæ件ä¸å å«äºè®¸å¤C代ç ç±è¾ å©ç¨åºåèæ¬çæã许å¤çç¼è¯æ¶é´é项影åè¿ä¸æå£ä»£ç èä¸å¿ é¡»å¨èåæ件ç»è£ åæä¾ç»ä»£ç çæå¨ãè¿ä¸ç³»åå¿ é¡»ä¼ ç»ä»£ç çæå¨çç¼è¯æ¶é´ç¸å ³çé项ä¼ä½¿å¾sqliteçåå¸çæ¬åä¸ç¸åï¼ä½æ¯å¨åè¿è¾¹æç« çæ¶åï¼ä»£ç çæå¨éè¦ç¥éçè¿ç»é项å æ¬ï¼
SQLITE_ENABLE_UPDATE_DELETE_LIMIT
SQLITE_OMIT_ALTERTABLE
SQLITE_OMIT_ANALYZE
SQLITE_OMIT_ATTACH
SQLITE_OMIT_AUTOINCREMENT
SQLITE_OMIT_CAST
SQLITE_OMIT_COMPOUND_SELECT
SQLITE_OMIT_EXPLAIN
SQLITE_OMIT_FOREIGN_KEY
SQLITE_OMIT_PRAGMA
SQLITE_OMIT_REINDEX
SQLITE_OMIT_SUBQUERY
SQLITE_OMIT_TEMPDB
SQLITE_OMIT_TRIGGER
SQLITE_OMIT_VACUUM
SQLITE_OMIT_VIEW
SQLITE_OMIT_VIRTUALTABLE
为äºæ建ä¸ä¸ªå®å¶çèåæ件ï¼å ä¸è½½åå§çç¬ç«æºç æ件å°ä¸ä¸ªunixæè ç±»unixå¼åå¹³å°ãç¡®å®è·åçåå§æºç æ件ä¸æ¯âé¢ç¼è¯è¿çæºæ件âãä»»ä½äººé½å¯ä»¥éè¿å°ä¸è½½é¡µæè ç´æ¥ä»configuration management system.è·åå®æ´çä¸å¥åå§æºç æ件ã
å设sqliteæºç æ 被åå¨ä¸ä¸ªå为âsqliteâçç®å½ä¸ã计åæ建ä¸ä¸ªå¹³è¡ç®å½ä¸çå为âbldâçèåæ件ãé¦å éè¿è¿è¡sqliteæºç æ ç§çconfigureèæ¬è¿è¡æè éè¿å¶ä½ä¸ä»½æºç æ 顶å±ççmakfile模æ¿çä¸ä»½ï¼æ¥æ建ä¸ä¸ªåéçmakefile.ç¶åæå¨ç¼è¾è¿ä¸ªMakfileå»å å«éè¦çç¼è¯æ¶é´ç¸å ³çé项ãæç»è¿è¡ï¼
make sqlite3.c
å¨windowsä¸ä½¿ç¨MSVC:
nmake /f Makefile.msc sqlite3.c
sqlite3.cçmake
targetä¼èªå¨æé ä¸è¬çâsqlite3.câå并çæºç æ件ï¼ä»¥åå®ç头æ件âsqlite3.hâï¼åå å«TCLæ¥å£çèåæºç æ件âtclsqlite3.câãä¹åï¼éè¦çæ件å¯ä»¥è¢«æ·è´å°æ件ç®å½ä¸ç¶åæ ¹æ®ä¸è¿°å¾åçè¿ç¨ç¼è¯ã
æ建ä¸ä¸ªwindowsçå¨æé¾æ¥åºDLL
为äºå¨windowsæ建ä¸ä¸ªsqliteçdll使ç¨ï¼é¦å è·å对åºçèåè¿çæºç æ件ï¼sqlit3.cåsqlite.hãè¿äºå¯ä»¥ä»SQLite websiteä¸ä¸è½½æè åä¸è¿°åç¥çä¸æ ·å»å®å¶çæã
使ç¨å·¥ä½ç®å½ä¸çæºç æ件ï¼ä¸ä¸ªdllå¯ä»¥å¨msvcä¸ä½¿ç¨å¦ä¸å½ä»¤çæï¼
cl sqlite3.c -link -dll -out:sqlite3.dll
ä¸è¿°å½ä»¤éè¦è¿è¡å¨msvcçMSVC Native Tools Command
Prompt.å¦ä½ä½ å·²ç»å¨æºå¨ä¸å®è£ äºmsvcï¼ä½ å¯è½æå¤ä¸ªçæ¬çè¿ç§å½ä»¤æ示符ï¼é对äºxåxçèªå¸¦æ建çï¼æè 交åç¼è¯å°ARMçãä¾èµè¦æ±çDLLå»ä½¿ç¨å¯¹åºåéçå½ä»¤æç¤ºç¬¦å·¥å ·ã
å¦æ使ç¨MinGWç¼è¯å¨ï¼å½ä»¤æ¯è¿æ ·çï¼
gcc -shared sqlite3.c -o sqlite3.dll
注æMinGWåªçæä½çdllãå¦æä¸ä¸ªåå¼çMinGWå·¥ç¨å¯ä»¥ç¨æ¥çæä½çdllãå¯ä»¥æ¨æå ¶å½ä»¤è¡è¯æ³æ¯ç±»ä¼¼çãéè¦æ³¨æçæ¯æè¿çMSVCççæ¬çæçDLLså¯è½ä¸è½å·¥ä½å°WinXPæè æ´æ©çæ¬çwindowsä¸ãå æ¤ä¸ºäºæ大é度çå ¼å®¹ä½ ççæçdllï¼æ¨èMinGWãä¸ä¸ªå¥½çç»éªæ³åæ¯ä½¿ç¨MinGWå»çæä½çdllsï¼ä½¿ç¨msvcå»çæä½çdllsã