2023-08-16 19:12:26 +02:00
|
|
|
# Notes On Compiling SQLite On Windows 11
|
|
|
|
|
|
|
|
Here are step-by-step instructions on how to build SQLite from
|
2024-10-10 11:59:06 +02:00
|
|
|
canonical source on a new Windows 11 PC, as of 2024-10-09:
|
2023-08-16 19:12:26 +02:00
|
|
|
|
|
|
|
1. Install Microsoft Visual Studio. The free "community edition"
|
|
|
|
will work fine. Do a standard install for C++ development.
|
|
|
|
SQLite only needs the
|
|
|
|
"cl" compiler and the "nmake" build tool.
|
|
|
|
|
|
|
|
2. Under the "Start" menu, find "All Apps" then go to "Visual Studio 20XX"
|
|
|
|
and find "x64 Native Tools Command Prompt for VS 20XX". Pin that
|
|
|
|
application to your task bar, as you will use it a lot. Bring up
|
|
|
|
an instance of this command prompt and do all of the subsequent steps
|
|
|
|
in that "x64 Native Tools" command prompt. (Or use "x86" if you want
|
|
|
|
a 32-bit build.) The subsequent steps will not work in a vanilla
|
|
|
|
DOS prompt. Nor will they work in PowerShell.
|
|
|
|
|
2024-10-25 17:28:00 +02:00
|
|
|
3. *(Optional):* Install TCL development libraries.
|
|
|
|
This note assumes that you will
|
2023-08-16 19:12:26 +02:00
|
|
|
install the TCL development libraries in the "`c:\Tcl`" directory.
|
|
|
|
Make adjustments
|
|
|
|
if you want TCL installed somewhere else. SQLite needs both the
|
2024-10-10 11:59:06 +02:00
|
|
|
"tclsh90.exe" command-line tool as part of the build process, and
|
|
|
|
the "tcl90.lib" and "tclstub.lib" libraries in order to run tests.
|
2024-10-25 17:28:00 +02:00
|
|
|
This document assumes you are working with TCL version 9.0.
|
2024-10-10 11:59:06 +02:00
|
|
|
See versions of this document from prior to 2024-10-10 for
|
|
|
|
instructions on how to build using TCL version 8.6.
|
2023-08-16 19:12:26 +02:00
|
|
|
<ol type="a">
|
|
|
|
<li>Get the TCL source archive, perhaps from
|
2024-10-17 18:22:47 +02:00
|
|
|
<https://www.tcl.tk/software/tcltk/download.html>
|
|
|
|
or <https://sqlite.org/tmp/tcl9.0.0.tar.gz>.
|
2023-08-16 19:12:26 +02:00
|
|
|
<li>Untar or unzip the source archive. CD into the "win/" subfolder
|
|
|
|
of the source tree.
|
|
|
|
<li>Run: `nmake /f makefile.vc release`
|
|
|
|
<li>Run: `nmake /f makefile.vc INSTALLDIR=c:\Tcl install`
|
2024-10-10 11:59:06 +02:00
|
|
|
<li><i>Optional:</i> CD to `c:\Tcl\bin` and make a copy of
|
|
|
|
`tclsh90.exe` over into just `tclsh.exe`.
|
|
|
|
<li><i>Optional:</i>
|
|
|
|
Add `c:\Tcl\bin` to your %PATH%. To do this, go to Settings
|
2023-08-16 19:23:42 +02:00
|
|
|
and search for "path". Select "edit environment variables for
|
|
|
|
your account" and modify your default PATH accordingly.
|
|
|
|
You will need to close and reopen your command prompts after
|
|
|
|
making this change.
|
2023-08-16 19:12:26 +02:00
|
|
|
</ol>
|
|
|
|
|
2024-10-25 17:28:00 +02:00
|
|
|
As of 2024-10-25, TCL is not longer required for many
|
|
|
|
common build targets, such as "sqlite3.c" or the "sqlite3.exe"
|
|
|
|
command-line tool. So you can skip this step if that is all
|
|
|
|
you want to build. TCL is still required to run "make test"
|
|
|
|
and similar, or to build the TCL extension, of course.
|
|
|
|
|
2023-08-16 19:12:26 +02:00
|
|
|
4. Download the SQLite source tree and unpack it. CD into the
|
|
|
|
toplevel directory of the source tree.
|
|
|
|
|
2024-10-25 17:28:00 +02:00
|
|
|
5. Run the "`Makefile.msc`" makefile with an appropriate target.
|
2023-08-16 19:12:26 +02:00
|
|
|
Examples:
|
|
|
|
<ul>
|
|
|
|
<li> `nmake /f makefile.msc`
|
|
|
|
<li> `nmake /f makefile.msc sqlite3.c`
|
2024-09-06 11:49:13 +02:00
|
|
|
<li> `nmake /f makefile.msc sqlite3.exe`
|
|
|
|
<li> `nmake /f makefile.msc sqldiff.exe`
|
2024-10-16 13:05:11 +02:00
|
|
|
<li> `nmake /f makefile.msc sqlite3_rsync.exe`
|
2024-10-25 17:28:00 +02:00
|
|
|
</ul>
|
|
|
|
<p>No TCL is required for the nmake targets above. But for the ones
|
|
|
|
that follow, you will need a TCL installation, as described in step 3
|
|
|
|
above. If you install TCL in some directory other than C:\\Tcl, then
|
|
|
|
you will also need to add the "TCLDIR=<i><dir></i>" option on the
|
|
|
|
nmake command line to tell nmake where your TCL is installed.
|
|
|
|
<ul>
|
2024-09-06 11:49:13 +02:00
|
|
|
<li> `nmake /f makefile.msc tclextension-install`
|
2023-08-16 19:12:26 +02:00
|
|
|
<li> `nmake /f makefile.msc devtest`
|
|
|
|
<li> `nmake /f makefile.msc releasetest`
|
2024-09-06 11:49:13 +02:00
|
|
|
<li> `nmake /f makefile.msc sqlite3_analyzer.exe`
|
2023-08-16 19:12:26 +02:00
|
|
|
</ul>
|
2023-08-18 13:36:33 +02:00
|
|
|
|
2024-09-06 11:49:13 +02:00
|
|
|
It is not required that you run the "tclextension-install" target prior to
|
|
|
|
running tests. However, the tests will run more smoothly if you do.
|
|
|
|
The version of SQLite used for the TCL extension does *not* need to
|
|
|
|
correspond to the version of SQLite under test. So you can install the
|
|
|
|
SQLite TCL extension once, and then use it to test many different versions
|
|
|
|
of SQLite.
|
|
|
|
|
|
|
|
|
2024-06-18 21:36:04 +02:00
|
|
|
7. For a debugging build of the CLI, where the ".treetrace" and ".wheretrace"
|
|
|
|
commands work, add the DEBUG=3 argument to nmake. Like this:
|
|
|
|
<ul>
|
|
|
|
<li> `nmake /f makefile.msc DEBUG=3 clean sqlite3.exe`
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
2023-08-18 13:36:33 +02:00
|
|
|
## 32-bit Builds
|
|
|
|
|
|
|
|
Doing a 32-bit build is just like doing a 64-bit build with the
|
|
|
|
following minor changes:
|
|
|
|
|
|
|
|
1. Use the "x86 Native Tools Command Prompt" instead of
|
|
|
|
"x64 Native Tools Command Prompt". "**x86**" instead of "**x64**".
|
|
|
|
|
|
|
|
2. Use a different installation directory for TCL.
|
|
|
|
The recommended directory is `c:\tcl32`. Thus you end up
|
|
|
|
with two TCL builds:
|
|
|
|
<ul>
|
|
|
|
<li> `c:\tcl` ← 64-bit (the default)
|
|
|
|
<li> `c:\tcl32` ← 32-bit
|
|
|
|
</ul>
|
|
|
|
|
2023-08-23 20:29:41 +02:00
|
|
|
3. Ensure that `c:\tcl32\bin` comes before `c:\tcl\bin` on
|
2023-08-18 13:36:33 +02:00
|
|
|
your PATH environment variable. You can achieve this using
|
|
|
|
a command like:
|
|
|
|
<ul>
|
|
|
|
<li> `set PATH=c:\tcl32\bin;%PATH%`
|
|
|
|
</ul>
|
2023-10-24 01:34:24 +02:00
|
|
|
|
2023-11-01 20:35:15 +01:00
|
|
|
## Building a DLL
|
|
|
|
|
|
|
|
The command the developers use for building the deliverable DLL on the
|
|
|
|
[download page](https://sqlite.org/download.html) is as follows:
|
|
|
|
|
|
|
|
> ~~~~
|
|
|
|
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"
|
|
|
|
~~~~
|
|
|
|
|
|
|
|
That command generates both the sqlite3.dll and sqlite3.def files. The same
|
|
|
|
command works for both 32-bit and 64-bit builds.
|
|
|
|
|
2023-10-24 01:34:24 +02:00
|
|
|
## Statically Linking The TCL Library
|
|
|
|
|
|
|
|
Some utility programs associated with SQLite need to be linked
|
|
|
|
with TCL in order to function. The [sqlite3_analyzer.exe program](https://sqlite.org/sqlanalyze.html)
|
|
|
|
is an example. You can build as described above, and then
|
|
|
|
enter:
|
|
|
|
|
|
|
|
> ~~~~
|
|
|
|
nmake /f Makefile.msc sqlite3_analyzer.exe
|
|
|
|
~~~~
|
|
|
|
|
|
|
|
And you will end up with a working executable. However, that executable
|
2024-10-10 11:59:06 +02:00
|
|
|
will depend on having the "tcl98.dll" library somewhere on your %PATH%.
|
2023-10-24 01:34:24 +02:00
|
|
|
Use the following steps to build an executable that has the TCL library
|
|
|
|
statically linked so that it does not depend on separate DLL:
|
|
|
|
|
|
|
|
1. Use the appropriate "Command Prompt" window - either x86 or
|
|
|
|
x64, depending on whether you want a 32-bit or 64-bit executable.
|
|
|
|
|
|
|
|
2. Untar the TCL source tarball into a fresh directory. CD into
|
|
|
|
the "win/" subfolder.
|
|
|
|
|
2024-10-10 11:59:06 +02:00
|
|
|
3. Run: `nmake /f makefile.vc OPTS=static shell`
|
2023-10-24 01:34:24 +02:00
|
|
|
|
|
|
|
4. CD into the "Release*" subfolder that is created (note the
|
|
|
|
wildcard - the full name of the directory might vary). There
|
2024-10-10 11:59:06 +02:00
|
|
|
you will find the "tcl90s.lib" file. Copy this file into the
|
|
|
|
same directory that you put the "tcl90.lib" on your initial
|
2023-10-24 01:34:24 +02:00
|
|
|
installation. (In this document, that directory is
|
|
|
|
"`C:\Tcl32\lib`" for 32-bit builds and
|
2023-10-24 01:34:53 +02:00
|
|
|
"`C:\Tcl\lib`" for 64-bit builds.)
|
2023-10-24 01:34:24 +02:00
|
|
|
|
|
|
|
5. CD into your SQLite source code directory and build the desired
|
2024-10-11 19:02:37 +02:00
|
|
|
utility program, but add the following extra argument to the
|
2023-10-24 01:34:24 +02:00
|
|
|
nmake command line:
|
|
|
|
<blockquote><pre>
|
2024-10-11 19:02:37 +02:00
|
|
|
STATICALLY_LINK_TCL=1
|
2023-10-24 01:34:24 +02:00
|
|
|
</pre></blockquote>
|
|
|
|
<p>So, for example, to build a statically linked version of
|
|
|
|
sqlite3_analyzer.exe, you might type:
|
|
|
|
<blockquote><pre>
|
2024-10-11 19:02:37 +02:00
|
|
|
nmake /f Makefile.msc STATICALLY_LINK_TCL=1 sqlite3_analyzer.exe
|
2023-10-24 01:34:24 +02:00
|
|
|
</pre></blockquote>
|
|
|
|
|
|
|
|
6. After your executable is built, you can verify that it does not
|
|
|
|
depend on the TCL DLL by running:
|
|
|
|
<blockquote><pre>
|
|
|
|
dumpbin /dependents sqlite3_analyzer.exe
|
|
|
|
</pre></blockquote>
|