Sampleextension is the "official" example of a Tcl extension. Write some C functions, and then follow the quick start guide below to add the required autogoo to get it to compile as an extension.

Note that the first link above is to the Fossil repository. Besides the files in that repository (they only make up the sample extension), you also need the tclconfig files in . The configure script expect the tclconfig files in either the current directory or a "tclconfig" subdirectory.

See Also

used by sampleextension
Extending Tcl
The main page for similar information
an alternative using CMake
Part of The Aries Engine (formerly the brick engine) repository


nightly snapshots (not up to date)


The Tcl sample extension implements an extension calculating the Core Secure Hash Algorithm (sha1). It demonstrates a TEA-conformant Tcl extension that includes a C library that can be dynamically loaded. It also illustrates the TEA directory structure and use of Tcl autoconf extensions to provide configure and make facilities.

Quick start guide

# Replace quux with the name of your extension
wget -qO-${EXTNAME}.tar.gz | tar xzv
wget -qO- | tar xzv
# Write your source files
# Edit
# If you use autoconf macros from other packages in[*]:
mv aclocal.m4 acinclude.m4
# Generate the configure script
# And then the usual:

[*] It's strange to me that the sampleextenstion code comes with a hand-crafted aclocal.m4. That file is normally generated by the aclocal command. If you need to run aclocal to pull in macros supplied by other packages (e.g. PKG_CHECK_MODULES()), you can move aclocal.m4 to acinclude.m4 and run aclocal. A new aclocal.m4 file will be generated that includes acinclude.m4 in addition to any external autoconf macros used in

The wget commands in the above fetch from the respective Fossil repositories, so they should be the latest stable version.

The tests/all.tcl file included in sampleextension is quite old and seems buggy (It always reports "Sourced 0 Test Files" for me). So you may want to replace this file with the version from a recent Tcl source distribution.