[Arjen Markus] (9 september 2002) Being an enthousiastic user of [Critcl], I ran into a small problem the other day: I needed to use a set of static (archive) libraries and the UNIX operating system I used (SUN Solaris) did not allow me to use them as part of a dynamic (shared) library. So, the solution was to create a "custom shell", with the static libraries linked into the shell, instead of them being a loadable extension. This page describes how I did this. The first step was to use [Critcl] with the option "-keepsrc 1" to keep the generated C source file. I renamed the file to "glue.c", this being the (unimaginative) name of the package I wanted. The second step was editing the file "tclAppInit.c", so that it would initialise my package as a static package: int Tcl_AppInit(interp) Tcl_Interp *interp; /* Interpreter for application. */ { ... /* * Call the init procedures for included packages. Each call should * look like this: * * if (Mod_Init(interp) == TCL_ERROR) { * return TCL_ERROR; * } * * where "Mod" is the name of the module. */ if (Glue_Init(interp) == TCL_ERROR) { return TCL_ERROR; } ... } (This required little more than copying and editing the example in the very file.) With the following commands, I got the custom shell I needed: cc -g -c tclAppInit.c -DUSE_TCL_STUBS cc -g -c glue.c -DUSE_TCL_STUBS f77 -g -o gluesh tclAppInit.o glue.o -L$TCLLIBPATH \ -ltcl8.3 -ltclstub8.3 libreader1.a libreader2.a -lm (slightly edited, irrelevant details have been omitted) Notes: * Even though "stubs" are enabled, you still need to link against the Tcl library itself, as the function Tcl_Main() is not contained in the stubs. * I use "f77" as the linker, because some of the libraries contain Fortran routines. "f77" takes care of including the Fortran run-time libraries. Running this custom shell requires, however, two more actions: * The environment variable LD_LIBRARY_PATH needs to point to the directory containing the Tcl shared library * As the shell is based on "tclAppInit.c", it expects to find a start-up script "init.tcl" somewhere among a list of fixed directories and directories relative to the location of the shell. The easiest (and laziest) way out was to create a soft-link to the installation directory containing Tcl on my system. ---- See also: [Building a custom tclsh] ---- [Category Tutorial]