Updated 2016-01-29 18:57:10 by pooryorick

How to compile Tcl and related C extensions on Windows presents tips and techniques, tool recommendations, etc. for compiling Tcl and related extensions on a Windows machine.

See Also  edit

Installing Tcl
How to build and install Tcl on various platforms
Building Tcl/Tk with Mingw
Microsoft C compiler and Tcl
Building Tcl DLL's for Windows
How to create mingw32 libraries from DLLs
Building Tcl and Tk 8.6 on Windows for R
Some notes by Adrian Wadell.

Overview  edit

The path of least resistance for building and testing Tcl on Windows is somewhat different, at least if you have VC++6. (It is rumored that a combination of MinGW and Cygwin make also works, but I've not tried it.)

On Windows with VC++6, the steps are:

  • download a copy of the Tcl zip or source file
  • create a directory where you plan on compiling the code
  • determine where you want to install the binaries
  • cd into the tcl top level directory
  • read the README file (and possibly the ChangeLog and changes files).
  • cd into the win directory
  • edit the first few lines of Makefile.vc to point correctly to the VC++6 installation and to where you want Tcl to be installed.
  • Run vcvars32.bat if you don't have the VC++6 environment set up in your startup.
  • Run setenv /retail if you don't have the win server 2000 sp1 platform sdk environment set up in your startup.
  • do nmake -f Makefile.vc all tcltest and investigate errors.
  • do nmake -f Makefile.vc test and investigate errors. Contact people on http://tcl.sf.net/, news:comp.lang.tcl or http://wiki.tcl.tk/ for help.
  • do nmake -f Makefile.vc install and resolve any errors.

./configure adds very little value on Windows systems, which are fairly homogeneous.

VC++  edit

See Also:
How to create a minimal Visual C++ install

Users that have VC++ installed can use it to build Tcl/Tk under Windows. Users that wish to use the gcc compiler to build Tcl/Tk under Windows should see Building Tcl/Tk with Mingw. Building Tcl/Tk under Cygwin is not supported.

Those who have the financial wherewithal to buy Visual C++ have been advocating its use, as the executables are better.

But wait--does use of Microsoft's C compiler require money? "Microsoft C compiler and Tcl"


To build Tcl using VC++ open a command prompt in the win directory of the source and type the following two commands:

First call vcvars32.bat to setup the environment. This is located in vc\bin of VC++ 5.0 or vc98\bin for VC++ 6.0.
Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.

Setting environment for using Microsoft Visual C++ tools.

Next, invoke the makefile, called makefile.vc:
D:\tcl_workspace\tcl_head_stock\win>nmake -f makefile.vc

Microsoft (R) Program Maintenance Utility   Version 6.00.8168.0
Copyright (C) Microsoft Corp 1988-1998. All rights reserved.

*** Compiler has 'Optimizations'
*** Compiler has 'Pentium 0x0f fix'
*** Linker has 'Win98 alignment problem'
*** Intermediate directory will be '.\Release\tcl_Dynamic'
*** Output directory will be '.\Release'
*** Suffix for binaries will be ''
*** Optional defines are ''
*** Dependency rules are not being used.

       cl -nologo -c -W3 -YX -Fp.\Release\tcl_Dynamic\ -QI0f -O2 -Op -Gs -MD -I
"..\win" -I"..\generic"  -Fo.\Release\tcl_Dynamic\tclAppInit.obj ..\win\tclAppIn
       rc -fo .\Release\tcl_Dynamic\tclsh.res -r -i "..\generic" -D__WIN32__  .
       cl -O2 -Op -Gs -nologo -c -W3 -YX -Fp.\Release\tcl_Dynamic\ -QI0f -Zl -D
STATIC_BUILD -I"..\win" -I"..\generic" -Fo.\Release\tcl_Dynamic\tclStubLib.obj .

Numerous targets and options exist. Read the top of makefile.vc itself for all the details.

HaO 2010-12-15: Since Tk 8.5, you need the win server 2000 sp1 platform sdk (How to create a minimal Visual C++ install) and and the command SetEnv.cmd /RELEASE (Annotated 10 steps to success with TEA).

This is not included in VC6 but might be in newer version of VC.

If you have VC6 and VC8 installed, and you want to compile with VC6, you have to add the following line to VCVARS32.bat of VC6 to make the SDK detect it (of cause, you have to adopt the path, this is my WIN 8.1 64 bit):
set DevEnvDir=c:\PROGRA~2\MICROS~2\Common\MSDev98

So you need that if setenv /RETAIL outputs:
C:\test>setenv /RETAIL
Attempting to detect a Microsoft Visual Studio installation
Setting environment for using Microsoft Visual Studio 2005 x86 tools.
Targeting Windows 2000 and IE 5.0 RETAIL

The correct output is:
C:\test>setenv /RETAIL
Targeting Windows 2000 and IE 5.0 RETAIL

The define of STATIC_BUILD is important when compiling with Visual C 6, as tcl.h does import and export macros differently based on the symbol. If you get unresolved references to _imp_SomeSymbol, this may be something worth pursuing for a resolution.

But STATIC_BUILD is set correctly by makefile.vc and the TEA build system already. The only point of contension is when one links to tcl84s.lib that -DSTATIC_BUILD should have been used on the sources when compiled for projects using Tcl. How Tcl builds itself is already managed by the makefiles. If in fact, one is compiling Tcl using an alternate method, yes, they had better set all the macros correctly and for that I agree. -- DG

HaO 2010-12-15: The title does not say How to Compile Tk, but when I try compiling Tk 8.5.9 debug with MS-VC6, win server 2000 sp1 platform sdk and the makefile in the win folder, I get the error debugging information corrupt; recompile module.

Shell trace:
C:\test\tk8.5.9\win>nmake -f makefile.vc release OPTS=symbols INSTALLDIR=c:\test\tcl859d TCLDIR=c:\test\tcl8.5.9
...(compile steps cut)...
link -nologo -machine:IX86  -debug:full -debugtype:cv -opt:nowin98 -dll -base:@"c:\test\tcl8.5.9\win\coffbase.txt",tk -out:".\Debug
    \tk85g.dll" kernel32.lib user32.lib gdi32.lib  "c:\test\tcl8.5.9\win\Debug\tclstub85.lib"
   Creating library .\Debug\tk85g.lib and object .\Debug\tk85g.exp
uuid.lib(cguid_i.obj) : fatal error LNK1103: debugging information corrupt; recompile module
NMAKE : fatal error U1077: 'link' : return code '0x44f'

Building MFCMAPI With Visual Studio 6, Stephen Griffin, 2006-08-03, proposes to exchange the library uuid.lib of the platform sdk by the version of vc98. This worked for me.

RS 2008-09-24: We see that self-compiled tclsh can no longer be run on a different target machine (both being Windows XP):
The system cannot execute the specified program.

In File Monitor, we see failed accesses to some .Manifest and .Config:
16:56:14        wish85.exe:1912        OPEN        C:\tmp\tcldist_8.5.4\bin\tclsh85.exe.Manifest        NOT FOUND        Options: Open  Access: 001200A9        
16:56:14        wish85.exe:1912        OPEN        C:\tmp\tcldist_8.5.4\bin\tclsh85.exe.Config        NOT FOUND        Options: Open  Access: 001200A9        

An ActiveTcl 8.5 could be installed without problem on the trouble machine. What do we do wrong? How to build tclsh so that it can be deployed to target machines?

LV In looking through tcl 8.5.4 source files, I run across this note in tcl/win/rules.vc:
# MSVC8 (ships with Visual Studio 2005) generates a manifest
# file that we should link into the binaries. This is how.

So that looks like the source of the error you are seeing. I don't know windows software development well enough to understand what a "manifest resource" is...

SUA  edit

Another option for some Windows users is Microsoft Subsystem for UNIX-based Applications (aka SUA), which is a POSIX environment around which a development community has grown. Many utilities commonly thought of as Unix tools are available for free download.

Unfortunately, Microsoft has chosen, for business reasons, to limit some of their platforms (I believe only 2 of the 7 Vista variants are able to use it) from using SUA. However, if you are using Microsoft XP, Server, or Vista Ultimate or Enterprise, you should take a look at it. The development community has a tool repository with an interface conceptually similar to CPAN or teacup.

Mingw/MSys  edit

JMN On windows NT & windows 2000; mingw/MSys, although a little clumsy to set up and maintain, was a reliable tool for building Tcl/TK.

Unfortunately, as of 2007-07, this toolchain doesn't seem to have kept up and doesn't appear to even launch properly on Vista 64bit.

In Compiling with mingw (WAS: Re: Problem with threads., comp.lang.tcl, 2002-05-28, Steve Blinkhorn, praised the Mingw C compiler (mingwin) distribution as being the way one can compile the same code on windows as well as various unix systems.

[Re: cross-platform compiles - Is there a version of mingw for MacOS? For Mac OS <=9, no there isn't (at least not that I know of), but for Mac OS X, of course there is 'gcc' as standard.]

Cygwin  edit

Many times Window developers attempt to compile Tcl and Tk using the Cygnus Cygwin Windows development environment, since that's what they use for other projects.

For reasons that at least one non-Windows developer does not understand, Tcl doesn't compile with the default Cygnus environment. Thus, people keep telling people to use the Mingw C compiler mentioned above.

GPS Tcl/Tk 8.4.1 and the CVS HEAD as of Jan/27/2003 compile with Cygwin for me. I've found that I can do a MinGW (using Cygwin's MinGW package) build while in Cygwin's XFree86 if after I run ./configure I edit the Makefile and add -mno-cygwin after gcc. I've even built some simple extensions using it.

Are there environments similar to Cygwin for Windows that allow one to compile Unix applications on Windows? For instance, I've heard references to David Korn's UWin .

LV: Besides UWin, there is Interix, aka SFU aka SUA I think now. This is a package that Microsoft makes available for free download now for Windows XP and Windows Server, and which they are incorporating into future releases. I suspect there are more.

TV: Cygwin IS capable of compiling serious unix applications to windows, and it is freely downloadable and since some time now comes with a easy to use installer app. Also, you can select to automatically install XFree86, ax xserver for direct and parallel use under windows, which can even accomodate KDE on windows, which worked, but I must fix mine after a cygwin upgrade. The xserver works networked, too, for instance if you want to access a linux machine on windows, you can adjust you DISPLAY variable to have windows on the other machine cross the net, which is good to develop multiple platform.

I did do a tcl/tk build under cygwin some time ago, I guess 8.0 or so, which I could complete with some minor warnings/errors (closing stdout or something stupid) with some work, though. If anyone did recently with success before I might throw in some time, I'd like to know.

Borland C Compiler  edit

Another popular free C compiler is the Borland C compiler. See Helmut Giese's comp.lang.tcl article titled Borland support: Wrapping it all up from Mon, 29 Jul 2002 19:29:28 GMT [1], in which Helmut volunteers info on using Borland compiler to build Tcl. In summer 2003, Helmut is working to make 8.5 generate correctly for Borland "out of the box".

lcc  edit

Also of potential interest are the lcc-win32 lcc compilers.

Cross-Compiling for Windows  edit

Another commonly discussed technique is using a Linux machine and cross compiling to generate Windows binaries. [Someone have some URLs or wiki references here?] See cross-compiling for a cook book for that.

I have seen notes indicating that Tcl and Tk can be compiled using the gcc free compiler in unix as well as Win32 (EGCS, FSF, cygwin32, mingw32) [There's duplication between this text and that in "C Language".] environments. Also, Win32's lcc should work. See

Packers  edit

[11] describes a variety of products of interest to those involved in application-level obfuscation, compression, and so on.