Creating Statically-Linked Interpreters
When writing a statically-linked interpreter, you must explicitly initialize all extensions that are statically linked with your application. Typically, this consists of adding code to your application's Tcl_AppInit procedure calling the extension's Init procedure and then calling TclStaticPackage to register the extension as a statically-linked package. Then at compilation, you must link your application with static versions of every library that your application needs.
For example, the main source file for a Tcl application that is statically linked with tbcload and [incr Tcl] contains code similar to the following that shown below. You would then need to link this application with the tbcload and [incr Tcl] libraries in addition to the Tcl library.
#include "tcl.h"
.
.
.
static int MyAppInit(Tcl_Interp *interp);
int
main(argc, argv)
int argc; /* Number of command-line arguments. */
char **argv; /* Values of command-line arguments. */
{
Tcl_Main(argc, argv, MyAppInit);
return 0; /* Needed only to prevent compiler warning. */
}
static int
MyAppInit(interp)
Tcl_Interp *interp; /* Interpreter for application. */
{
if (Tcl_Init(interp) == TCL_ERROR) {
return TCL_ERROR;
}
if (Tbcload_Init(interp) == TCL_ERROR) {
return TCL_ERROR;
}
Tcl_StaticPackage(interp, "tbcload", Tbcload_Init,
Tbcload_SafeInit);
if (Itcl_Init(interp) == TCL_ERROR) {
return TCL_ERROR;
}
Tcl_StaticPackage(interp, "Itcl", Itcl_Init, Itcl_SafeInit);
.
.
.
return TCL_OK;
}
http://www.ajubasolutions.com Voice: (650) 210-0100 Fax: (650) 210-0101 support@ajubasolutions.com |