interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / doc / compile-for-windows.md

186 lines · 8474 bytes Raw Blame History Rendered
1# Notes On Compiling SQLite On Windows 11
2
3## Executive Summary
4
5 1. Install Microsoft Visual Studio
6 2. Get a "Native Tools Command Prompt"
7 3. Get a tarball of the canonical SQLite source tree and unpack it
8 4. Run commands like: <ul>
9 <li> `make sqlite3.c`
10 <li> `make sqlite3.exe`
11 <li> `make sqlite3.dll`</ul>
12
13## Details For Standard 64-bit Builds On Either x64 Or ARM
14
15Below are step-by-step instructions on how to build SQLite from
16canonical source on a new Windows 11 PC, as of 2026-08-01.
17See [](./compile-for-unix.md) for a similar guide for unix-like
18systems, including MacOS.
19
20 1. Install Microsoft Visual Studio. The free "community edition"
21 will work fine. Do a standard install for C++ development.
22 SQLite only needs the
23 "cl" compiler and the "nmake" build tool.
24 <ul><li><b>Note:</b>
25 VS2015 or later is required for the procedures below to
26 all work. You *might* be able to get the build to work with
27 earlier versions of MSVC, but in that case the TCL installation
28 of step 3 will be required, since the "jimsh0.c" program of
29 Autosetup that is used as a substitute for "tclsh.exe" won't
30 compile with versions of Visual Studio prior to VS2015. In any
31 event, building SQLite from canonical source code on Windows
32 is not supported for earlier versions of Visual Studio.</ul>
33
34 2. Under the "Start" menu, find "All Apps" then go to "Visual Studio 20XX"
35 and find "x64 Native Tools Command Prompt for VS 20XX". Pin that
36 application to your task bar, as you will use it a lot. Bring up
37 an instance of this command prompt and do all of the subsequent steps
38 in that "x64 Native Tools" command prompt. (Or use "x86" if you want
39 a 32-bit build. Or use "ARM64" if you want to do a build for Windows
40 on ARM.) The subsequent steps will not work in a vanilla
41 DOS prompt. Nor will they work in PowerShell.
42
43 3. *(Optional):* Install TCL development libraries.
44 This note assumes that you will
45 install the TCL development libraries in the "`c:\Tcl`" directory.
46 Make adjustments
47 if you want TCL installed somewhere else. SQLite needs both the
48 "tclsh90.exe" command-line tool as part of the build process, and
49 the "tcl90.lib" and "tclstub.lib" libraries in order to run tests.
50 This document assumes you are working with TCL version 9.0.
51 See [](./tcl-extension-testing.md#windows) for guidance on how
52 to compile TCL version 8.6 for use with SQLite.
53 <ol type="a">
54 <li>Get the TCL source archive, perhaps from
55 <https://www.tcl.tk/software/tcltk/download.html>
56 or <https://sqlite.org/tmp/tcl9.0.0.tar.gz>.
57 <li>Untar or unzip the source archive. CD into the "win/" subfolder
58 of the source tree.
59 <li>Run: `nmake /f makefile.vc INSTALLDIR=c:\Tcl release`
60 <li>Run: `nmake /f makefile.vc INSTALLDIR=c:\Tcl install` <br>
61 Notes:
62 <ol type="i">
63 <li> The previous two `nmake` commands must be run separately.
64 <li> Also, the INSTALLDIR=... argument is required on both.
65 </ol>
66 <li><i>Optional:</i> CD to `c:\Tcl\bin` and make a copy of
67 `tclsh90.exe` over into just `tclsh.exe`.
68 <li><i>Optional:</i>
69 Add `c:\Tcl\bin` to your %PATH%. To do this, go to Settings
70 and search for "path". Select "edit environment variables for
71 your account" and modify your default PATH accordingly.
72 You will need to close and reopen your command prompts after
73 making this change.
74 </ol>
75
76 As of 2024-10-25, TCL is not longer required for many
77 common build targets, such as "sqlite3.c" or the "sqlite3.exe"
78 command-line tool. So you can skip this step if that is all
79 you want to build. TCL is still required to run "make test"
80 and similar, or to build the TCL extension, of course.
81
82 4. Download the SQLite source tree and unpack it. CD into the
83 toplevel directory of the source tree.
84
85 5. The source tree contains the "`make.bat`" batch script that
86 simulations the behavior of Unix-style "make" using "`nmake`".
87 So the build process for Windows is the same as for Unix:
88 <ul>
89 <li> `make sqlite3.c`
90 <li> `make sqlite3.exe`
91 <li> `make sqldiff.exe`
92 <li> `make sqlite3_rsync.exe`
93 </ul>
94 <p>No TCL is required for the make targets above. But for the ones
95 that follow, you will need a TCL installation, as described in step 3
96 above. If you install TCL in some directory other than C:\\Tcl, then
97 you will also need to add the "TCLDIR=<i>&lt;dir&gt;</i>" option on the
98 nmake command line to tell nmake where your TCL is installed.
99 <ul>
100 <li> `make tclextension-install`
101 <li> `make test`
102 <li> `make releasetest`
103 </ul>
104
105 It is not required that you run the "tclextension-install" target prior to
106 running tests. However, the tests will run more smoothly if you do.
107 The version of SQLite used for the TCL extension does *not* need to
108 correspond to the version of SQLite under test. So you can install the
109 SQLite TCL extension once, and then use it to test many different versions
110 of SQLite.
111
112
113 7. For a debugging build of the CLI, where the ".treetrace" and ".wheretrace"
114 commands work, add the DEBUG=3 argument to nmake. Like this:
115 <ul>
116 <li> `make DEBUG=3 clean sqlite3`
117 </ul>
118
119## 32-bit Builds
120
121Doing a 32-bit build is just like doing a 64-bit build with the
122following minor changes:
123
124 1. Use the "x86 Native Tools Command Prompt" instead of
125 "x64 Native Tools Command Prompt". "**x86**" instead of "**x64**".
126
127 2. Use a different installation directory for TCL.
128 The recommended directory is `c:\tcl32`. Thus you end up
129 with two TCL builds:
130 <ul>
131 <li> `c:\tcl` &larr; 64-bit (the default)
132 <li> `c:\tcl32` &larr; 32-bit
133 </ul>
134
135 3. Ensure that `c:\tcl32\bin` comes before `c:\tcl\bin` on
136 your PATH environment variable. You can achieve this using
137 a command like:
138 <ul>
139 <li> `set PATH=c:\tcl32\bin;%PATH%`
140 </ul>
141
142## Building a DLL
143
144The command the developers use for building the deliverable DLL on the
145[download page](https://sqlite.org/download.html) is as follows:
146
147> nmake /f Makefile.msc sqlite3.dll USE_NATIVE_LIBPATHS=1 "OPTS=-DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_FTS4=1 -DSQLITE_ENABLE_FTS5=1 -DSQLITE_ENABLE_RTREE=1 -DSQLITE_ENABLE_JSON1=1 -DSQLITE_ENABLE_GEOPOLY=1 -DSQLITE_ENABLE_SESSION=1 -DSQLITE_ENABLE_PREUPDATE_HOOK=1 -DSQLITE_ENABLE_SERIALIZE=1 -DSQLITE_ENABLE_MATH_FUNCTIONS=1"
148
149That command generates both the sqlite3.dll and sqlite3.def files. The same
150command works for both 32-bit and 64-bit builds.
151
152## Linking Against ZLIB
153
154Some feature (such as zip-file support in the CLI) require the ZLIB
155compression library. That library is more or less universally available
156on unix platforms, but is seldom provided on Windows. You will probably
157need to provide it yourself. Here the the steps needed:
158
159 1. Download the zlib-1.3.1.tar.gz tarball (or a similar version).
160 Unpack the tarball sources. You can put them wherever you like.
161 For the purposes of this document, let's assume you put the source
162 tree in c:\\zlib-64. Note: If you are building for both x64 and
163 x86, you will need separate builds of ZLIB for each, thus separate
164 build directories.
165
166 2. Before building SQLite (as described above) first make these
167 environment changes. The lead-programmer for SQLite (who writes
168 these words) has BAT files named "env-x64.bat" and "env-x32.bat"
169 and "env-arm64.bat" that make these changes, and he runs those
170 BAT file whenever he starts a new shell. These are the settings
171 needed:
172 <blockquote>
173 set USE_ZLIB=1<br>
174 set BUILD_ZLIB=0<br>
175 set ZLIBDIR=c:\\zlib-64
176 </blockquote>
177
178 3. Because the settings in step 2 specify "BUILD_ZLIB=0", you will need
179 to build the library at least once. I recommand:
180 <blockquote>
181 make clean sqlite3.exe BUILD_ZLIB=1
182 </blockquote>
183
184 4. After making the environment changes specified in steps 1 through 3
185 above, you then build and test SQLite as you normally would. The
186 environment variable changes will cause ZLIB to be linked automatically.