Building TCL/TK 8.6.4 with Visual Studio 2013

Downloads

For the impatient:

Prerequisites

  1. You need Visual Studio 2013.1. I cannot believe I am writing this down as a prerequisite on a page that has the title building TCL/TK 8.6.4 with Visual Studio 2013.1.
  2. You need the TCL/TK sourcecode. In the following, I am using Tcl 8.6.4 and Tk 8.6.4
  3. Unzip the sourcecode. At the end, you should have two directories, for example c:\tk8.6.4 and c:\tcl8.6.4.

The thing with GetVersion

If you try to build the plain vanilla sources in the build environment indicated above, you'll run into a problem: on Windows 8.1, GetVersion and GetVersionEx are deprecated. If you do a short grep on the

And in the TK source, you'll find this:

c:\tk8.6.4\win>grep GetVersion *.c
nmakehlp.c:static const char *GetVersionFromFile(const char *filename, const char *match, int numdots);
nmakehlp.c:         printf("%s\n", GetVersionFromFile(argv[2], argv[3], *(argv[1]+2) - '0'));
nmakehlp.c: * GetVersionFromFile --
nmakehlp.c:GetVersionFromFile(
tkWinColor.c:   int version = LOBYTE(LOWORD(GetVersion()));
tkWinDialog.c:    if (LOBYTE(LOWORD(GetVersion())) < 5) {
tkWinMenu.c:    GetVersionEx(&os);
tkWinX.c:    GetVersionEx(&os);
tkWinX.c:       GetVersionEx(&os);
ttkWinXPTheme.c:    GetVersionEx(&os);

Well, despair not: there is a nice article on codeproject.com that gives you all the background information you'd ever want. In particular, it points out that using a pragma to disable the warning has the benefit that your code continues to run on earlier versions of Windows, which, given widespread adoption or rather lack thereof of Windows 8.x is definitely the preferred option.

So, for example, in apps/apps.c, I changed this:

    if (LOBYTE(LOWORD(GetVersion())) < 5) {

simply to this:

#pragma warning (disable : 4996)        
    if (LOBYTE(LOWORD(GetVersion())) < 5) {
#pragma warning (default : 4996) 

Notes:

  1. I wrote a script that changes the TCL/TK code for these patches, available for download.

So with these changes out of the way, let's get started.

Building the 32-bit version

  1. Open CMD.EXE in the directory C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin
  2. Run vcvars32.bat
  3. Change to the win subdirectory in the TCL source folder. For example, for me this is C:\tcl8.6.4\win
  4. Run nmake -f makefile.vc
  5. Change to the win subdirectory in the TK source folder. For example, for me this is C:\tk8.6.4\win
  6. Run set TCLDIR=..\..\tcl8.6.4 to ensure TK finds TCL.
  7. Run nmake -f makefile.vc
  8. Note: you can stop reading here if you only need the release build. The next few steps show you how to build the debug binaries as well.
  9. Change to the win subdirectory in the TCL source folder. For example, for me this is C:\tcl8.6.4\win
  10. Run nmake -f makefile.vc OPTS=symbols
  11. Change to the win subdirectory in the TK source folder. For example, for me this is C:\tk8.6.4\win
  12. Run nmake -f makefile.vc OPTS=symbols

Building the 64-bit version

  1. Open CMD.EXE in the directory C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64
  2. Run vcvars64.bat
  3. Change to the win subdirectory in the TCL source folder. For example, for me this is C:\tcl8.6.4\win
  4. Run nmake -f makefile.vc MACHINE=AMD64
  5. Change to the win subdirectory in the TK source folder. For example, for me this is C:\tk8.6.4\win
  6. Run set TCLDIR=..\..\tcl8.6.4 to ensure TK finds TCL.
  7. Run nmake -f makefile.vc MACHINE=AMD64
  8. Note: you can stop reading here if you only need the release build. The next few steps show you how to build the debug binaries as well.
  9. Change to the win subdirectory in the TCL source folder. For example, for me this is C:\tcl8.6.4\win
  10. Run nmake -f makefile.vc MACHINE=AMD64 OPTS=symbols
  11. Change to the win subdirectory in the TK source folder. For example, for me this is C:\tk8.6.4\win
  12. Run nmake -f makefile.vc MACHINE=AMD64 OPTS=symbols