Building VTK 2.x
with Tcl/Tk 8.0.x (Windows)

Introduction

The VTK is
a great toolkit which covers dozens of graphics and visualization techniques
and helps you to build powerful C++ or Tcl/Tk
applications. Tcl is an interpretive framework designed to
provide a flexible command language that may be easily integrated with
a variety of applications. Tk is a window system independent
extension of Tcl which provides support for common user interface
components and helps you to build portable interface or prototypes in
a couple of minutes. The combination of VTK and Tcl/Tk
might lead to very impressive results.

Note : as of October, 17th 1998, the latest stable
releases are VTK 2.1 and Tcl/Tk
8.0.3. VTK 2.0 was the major release following
VTK 1.2. In the same manner Tcl/Tk 8.0 was
the unified successor of both Tcl 7.6 and Tk 4.2.
Tcl/Tk 8.0.x includes very interesting features and enhancements
like an automatic bytecode compiler (speedups of 2 to 10x), namespaces,
binary I/O, random numbers, registry support, HTTP support, native GUI
support, and many others.

This paper covers some difficulties that might be encountered while
trying to rebuild VTK 2.x dynamic libraries (Windows .dll)
agains a new Tcl/Tk 8.0.x distributions. Rebuilding VTK
might also be interesting in the following cases :

[P0: rebuild fever]

Wanna modify some VTK internals ? Wanna give your CPU and swap disk
some hard work ? Or are you just a Tcl/Tk addict, unable
to live without the very latest distribution :) ? Let's rebuild the whole
stuff.

[P1: VTK 2.0 support]

The latest official release, VTK 2.0, was designed to
work with Tcl 7.6 and Tk 4.2. Since
then a new major release of Tcl/Tk was made available
in August 1997 : Tcl/Tk 8.0 includes very interesting
features but it also introduces some incompatibilities that prevents
any useful combination with VTK 2.0 (hence, both
may not be installed on the same system). Hopefully, the VTK
release scheme was slightly updated so that one could download
the current developing version (as a "nightly update").
This "nightly release" is not as tested as an official
release, but allows anyone to have access to the latest modifications
or bug fixes. Among these modifications was the Tcl/Tk 8.0
support introduced (which is official in the current stable release,
VTK 2.1). You definitely should download VTK
2.1, but if you still want to work with one of these VTK
2.0 nightly release this paper might be of some help.

[P2: VTK 2.1-Tcl/Tk 8.0.3 incompatibilities]

This problem is still unexplained, and you might not be concerned.
The Windows VTK 2.1 binary distribution (vtk21.exe)
comes with Tcl/Tk 8.0.2 support. It includes wish80.exe
(in VTK/lib/) known as the usual Tcl/Tk
script launcher invoked when clicking on .tcl
files. But wish80.exe is ALSO provided
by any Tcl/Tk binary distribution (check your Tcl/bin/
directory). Which one should you use ? That seems to be the problem...
The VTK 2.1 installer creates an association between .tcl
files and its wish80.exe, thus breaking
the old association between this kind of file and the wish80.exe
installed by your current Tcl/Tk distribution. It is harmless
for most people, as you might click on both VTK or pure
Tcl/Tk scripts, and VTK 2.1's wish80.exe
will do the job.

But what happens if you decide to upgrade to a new Tcl/Tk
version, say Tcl/Tk 8.0.3, or to a customized Tcl/Tk
launcher, like the one provided with the [Itcl]
package (itkwish80.exe) ? They are some
chances that a new association will be made between .tcl
files and the new wish80.exe. You may
also have no choice and have to use this new Tcl/Tk
launcher (to work with [Itcl] for example). Theoritically
this might NOT be a problem, as the VTK 2.1.dll
are loaded on the fly when invoking the "catch {load vtktcl}"
instructions located in your scripts, and that should be irrelevant to
the launcher. But believe it or not, this does NOT WORK for me with the
current binary distributions (VTK 2.1 + Tcl/Tk 8.0.3
or [Itcl] 3.0) ! If I try to launch VTK scripts
using a different wish80.exe, it will
CRASH most of the time. And I do not know why for the moment... It seems
to me that the format of the .dll is involved,
as if you rebuild the VTK 2.1 against the new Tcl/Tk
8.0.3 distribution, it will work.

Thanks to Jonathan M. Gilligan, Dr. Kenneth M. Martin and the VTK
mailing list for helping me finding a solution to my problems (there might
be many other clever solutions, but this one seems to work).

Requirements

Windows 95/NT

Visual C++ (do not forget to run vcvars32.bat
or put devstudio\vc\bin into your path
before using it at the command prompt)

I will use the following places as installation/uncompressing directories
:

Sadly, the binary distribution does not come with the necessary header
for VTK 2.x to be compiled or rebuilt. Furthermore, it is
provided with a set of static libraries that MAY not have been built using
the right "calling method" (at this time, this is no more the
case in Tcl/Tk 8.0.3 : libraries are "correct").
I will therefore definitely advise you to download the source package
too, as you MAY have to (re)compile it, and/or you WILL have to use some
of its files.

You might first perform some tests to check if you really need to rebuild
your Tcl/Tk 8.0.x distribution from the source package :

Test the binary distribution

If you were using any previous version of Tcl/Tk, you better
uninstall it NOW. Make SURE you removed ANY Tcl/Tk.dll
(tclxx.dll, tkxx.dll)
from your windows/system (or windows/system32)
directory ! Check it twice. If your new Tcl/Tk distribution
is already installed, make sure you removed any duplicated .dll
: your Tcl/bin directory shall be full of .dll, check
that you destroyed oldest .dll (with the same name) that might
be found in your windows/system (or windows/system32)
directory.

Install the pre-compiled binary distribution. It comes with one or two
set of static libraries (located in c:\tcl\lib,
your mileage may vary) :

tcl80vc.lib, tk80vc.lib : built and
linked with Visual C++

(optional) tcl80.lib, tk80.lib : built
and linked with Borland C++

Run the following commands at the command prompt :

> cd c:\tcl\lib
> dumpbin /SYMBOLS tk80vc.lib | grep -i winchild

If the output looks like the excerpt below (which is the case with Tcl/Tk
8.0.3), you are definitely lucky as the libraries were built using
the _stdcall calling convention (notice the ending @16
sign) and you might proceed directly to the VTK section
(but remember that you will also need the source package to get the necessary
include files) :

If the output looks like this (which was the case with Tcl/Tk
8.0.0, and is no more with Tcl/Tk 8.0.3), you are
in trouble, as the libraries were built using the _cdecl
calling convention (there is no ending @16 sign). Proceed
to the following build section :

Build the source distribution

You better uninstall the binary distribution you might have tested in
the previous step.

Building the source distribution is straightforward. Download both Tcl/Tk
8.0.x source packages (tcl8.0.x.tar.gz,
tk8.0.x.tar.gz), unzip and untar them (I
will use c:\tcl8.0.x and c:\tk8.0.x
as installation/uncompressing directories), have a look at both readme's,
edit a couple of makefile's and you are
done in a few minutes. Do not forget to put the dynamic libraries (tcl80.dll,
tk80.dll) in your system directory, and
the binaries (tclsh80.exe, wish80.exe)
somewhere along your PATH. Test some Tcl/Tk
scripts.

You might thereafter perform some tests to check if the static libraries
were built accordingly. These are the same as described in the previous
section (notice that these fresh static libraries may now be called tcl80.lib
and tk80.lib instead of tcl80vc.lib
and tk80vc.lib, as found in the binary
distribution). Run the following commands at the command prompt :

the latest source version archived every night and available in the
nightly update
page (unsupported),

(optional) an official/stable 2.x binary distribution for Windows
(ex : vtk21.exe), which is not necessary
as we are trying to rebuild the VTK from the sources.

You better uninstall any previous VTK binary distribution
first ([P2] in order to get rid of the VTK's
wish80.exe and any related file associations).

Download the sources, unzip and untar them. I will refer to the VTK
2.x source directory as c:\vtk.
The PC (Windows) installation procedure is described in the according
section in c:\vtk\README.html. Read it
carefully. I will use c:\vtkbin as the
"libraries build directory".

Link to the Tcl/Tk 8.0.x
libraries

Depending on your problem :

[P1: VTK 2.0 support]

The VTK 2.0 source package already includes static libraries
for Tcl 7.6/Tk 4.2 (c:\vtk\pcmaker\tcl76.lib,
and c:\vtk\pcmaker\tk42.lib) as well as
the corresponding headers (c:\vtk\pcmaker\xlib\*.h).
It is obvious that building the VTK with this set of old
files will conflict with your current Tcl/Tk 8.0.x installation.

[P0: rebuild fever], [P2: VTK 2.1-Tcl/Tk
8.0.3 incompatibilities]

The VTK 2.1 source package has Tcl/Tk 8.0.2
support, and therefore includes static libraries (c:\vtk\pcmaker\tcl80.lib,
and c:\vtk\pcmaker\tk80.lib) as well as
the corresponding headers (c:\vtk\pcmaker\xlib\*.h).
But what you want is rebuilding the VTK 2.1 against your
new Tcl/Tk 8.0.x system.

Hopefully, the pcmaker.exe front-end
gives you the opportunity to provide the paths to some of your current
Tcl/Tk 8.0.x files by filling two entries after the "Where
is libtcl" and "Where is libtk" labels (see dialog) :

The contents of these entries will depend on how you installed the Tcl/Tk
8.0.x system (from the binary distribution or after rebuilding
the source package). But you might first want to understand how pcmaker.exe
is handling these values :

Understanding pcmaker

Building VTK 2.x with Tcl/Tk 8.0.x support
involves using both static libraries (*.lib)
and header files (i.e. include files, *.h).
You may provide pcmaker both paths to the
static libraries through these entries, but how can it also find the include
files ? This is the tricky part :) pcmaker
makes some assumptions regarding the paths to these static libraries :
it expects these paths to contain a "win"
component, and will use this "win"
part to split the whole name and build some new paths to the directories
holding the include files (generic and
xlib). It does so because it is expecting
the following directory structure :

Why this particular structure ? Because this exactly matchs the actual
Tcl/Tk 8.0.x directory structure found in the source distributions
!

As stated before, the contents of these "Where is libtcl"
and "Where is libtk" entries will depend on how you installed
the Tcl/Tk 8.0.x :

You did NOT rebuild the Tcl/Tk 8.0.x source distribution

If your Tcl/Tk 8.0.x binary distribution was correct (which
should be the case with Tcl/Tk 8.0.3) and therefore you did
not have to rebuild the entire source distribution (see the previous "Dealing
with Tcl/Tk 8.0.x" section), then you should follow
these instructions :

The current Tcl/Tk 8.0.x binary distribution does not come
with the necessary header files. Download both Tcl/Tk
8.0.x source packages (tcl8.0.x.tar.gz,
tk8.0.x.tar.gz), unzip and untar them (I
will use c:\tcl8.0.x and c:\tk8.0.x
as installation/uncompressing directories). You will have to extract files
from the source packages and put both binary (static libraries) and source
files (include files) in a special directory structure, which will reflect
the intended structure explained in the previous section (both Tcl
and Tk related files will be mixed in the same directories)
:

make a fake Tcl-VTK directory. Example :
c:\tcl8.0.x-for-vtk

put the following generic include files from the source packages to
c:\tcl8.0.x-for-vtk\generic\
:

c:\tcl8.0.x\generic\ : tcl.h,
tclInt.h, tclPort.h

c:\tk8.0.x\generic\ : tk.h,
tkInt.h, tkPort.h

put the following Windows-specific include files from
the source packages to c:\tcl8.0.x-for-vtk\win\
:

c:\tcl8.0.x\win\ : tclWinInt.h,
tclWinPort.h

c:\tk8.0.x\win\ : tkWin.h,
tkWinInt.h, tkWinPort.h

put the static libraries provided with the binary distribution (c:\tcl\lib\*.lib)
to c:\tcl8.0.x-for-vtk\win\

put the X11-specific include files from the source packages
(c:\tk8.0.x\xlib\) to c:\tcl8.0.x-for-vtk\xlib\

Follow the usual compilation process and you are done ([P2]
Try to force the association between .tcl
files and the official wish80.exe provided
by Tcl/Tk 8.0.x distribution, make sure that any previous
VTK's wish80.exe has been
deleted) ! Skip the next section.

Note : there was also another solution, preventing you from creating
this "fake" directory structure. Just replace the Tcl/Tk
8.0.x files found in the VTK 2.x source package under
c:\vtk\pcmaker\ with these from both the
new Tcl/Tk 8.0.x binary distribution (static librairies)
and sources packages (include files).

You DID rebuild the Tcl/Tk 8.0.x source distribution

You did have to rebuild the Tcl/Tk 8.0.x distribution (which
should not be necessary with Tcl/Tk 8.0.3). Then the rest
will be straightforward : you were using the sources packages, and their
directory structures are exactly what pcmaker
is wanting. Run pcmaker as usual, and use :

Follow the usual compilation process and you are done ([P2]
Try to force the association between .tcl
files and the official wish80.exe provided
by Tcl/Tk 8.0.x distribution, make sure that any previous
VTK's wish80.exe has been
deleted) !