SWIG Tcl Examples

$Header: /cvs/projects/SWIG/Examples/tcl/index.html,v 2001/12/08 23:33:37 cheetah Exp $

The following examples illustrate the use of SWIG with Tcl.

  • simple. A minimal example showing how SWIG can be used to wrap a C function and a global variable.
  • constants. This shows how preprocessor macros and certain C declarations are turned into constants.
  • variables. How SWIG can be used to wrap C global variables.
  • value. How to pass and return structures by value.
  • class. How wrap a simple C++ class.
  • reference. C++ references.
  • pointer. Simple pointer handling.
  • funcptr. Pointers to functions.

Compilation Issues

  • To create a Tcl extension, SWIG is run with the following options:
    % swig -tcl interface.i
  • Please see the Windows page in the main manual for information on using the examples on Windows.

  • The compilation of examples is done using the file Example/Makefile. This makefile performs a manual module compilation which is platform specific. Typically, the steps look like this (Linux):
    unix % swig -tcl interface.i
    unix % gcc -fpic -c interface_wrap.c -I/usr/local/include
    unix % gcc -shared interface_wrap.o $(OBJS) -o
    unix % tclsh8.3
    % load ./
    % blah ...


The examples have been extensively tested on the following platforms:
  • Linux
  • Solaris
Your mileage may vary. If you experience a problem, please let us know by sending a message to