NAME
load - Load machine code and initialize new commands.
SYNOPSIS
llooaadd fileName llooaadd fileName packageName llooaadd fileName packageName interpDESCRIPTION
This command loads binary code from a file into the application's
address space and calls an initialization procedure in the package to incorporate it into an interpreter. fileName is the name of the file containing the code; its exact form varies from system to system but on most systems it is a shared library, such as a ..ssoo file underSolaris or a DLL under Windows. packageName is the name of the pack-
age, and is used to compute the name of an initialization procedure.interp is the path name of the interpreter into which to load the pack-
age (see the iinntteerrpp manual entry for details); if interp is omitted, it defaults to the interpreter in which the llooaadd command was invoked.Once the file has been loaded into the application's address space, one
of two initialization procedures will be invoked in the new code. Typ-
ically the initialization procedure will add new commands to a Tcl interpreter. The name of the initialization procedure is determined by packageName and whether or not the target interpreter is a safe one. For normal interpreters the name of the initialization procedure will have the form pkgIInniitt, where pkg is the same as packageName except that the first letter is converted to upper case and all other letters are converted to lower case. For example, if packageName is ffoooo or FFOOoo, the initialization procedure's name will be FFooooIInniitt. If the target interpreter is a safe interpreter, then the name of the initialization procedure will be pkgSSaaffeeIInniitt instead of pkgIInniitt. ThepkgSSaaffeeIInniitt function should be written carefully, so that it initial-
izes the safe interpreter only with partial functionality provided bythe package that is safe for use by untrusted code. For more informa-
tion on Safe-Tcl, see the ssaaffee manual entry.
The initialization procedure must match the following prototype: typedef int TclPackageInitProc(TclInterp *interp); The interp argument identifies the interpreter in which the package isto be loaded. The initialization procedure must return TTCCLLOOKK or
TTCCLLEERRRROORR to indicate whether or not it completed successfully; in the event of an error it should set the interpreter's result to point to an error message. The result of the llooaadd command will be the result returned by the initialization procedure.The actual loading of a file will only be done once for each fileName
in an application. If a given fileName is loaded into multiple inter-
preters, then the first llooaadd will load the code and call the initial-
ization procedure; subsequent llooaadds will call the initialization pro-
cedure without loading the code again. It is not possible to unload or
reload a package.
The llooaadd command also supports packages that are statically linked with the application, if those packages have been registered by calling the TTccllSSttaattiiccPPaacckkaaggee procedure. If fileName is an empty string, then packageName must be specified. If packageName is omitted or specified as an empty string, Tcl tries toguess the name of the package. This may be done differently on differ-
ent platforms. The default guess, which is used on most UNIX plat-
forms, is to take the last element of fileName, strip off the first three characters if they are lliibb, and use any following alphabetic and | underline characters as the module name. For example, the command llooaadd lliibbxxyyzz44..22..ssoo uses the module name xxyyzz and the command llooaadd bbiinn//llaasstt..ssoo {{}} uses the module name llaasstt. If fileName is an empty string, then packageName must be specified. |The llooaadd command first searches for a statically loaded package (one |
that has been registered by calling the TTccllSSttaattiiccPPaacckkaaggee procedure) by | that name; if one is found, it is used. Otherwise, the llooaadd command |searches for a dynamically loaded package by that name, and uses it if |
it is found. If several different files have been llooaadded with differ- |
ent versions of the package, Tcl picks the file that was loaded first.
PPOORRTTAABBIILLIITTYY IISSSSUUEESS WWiinnddoowwssWhen a load fails with "library not found" error, it is also
possible that a dependent library was not found. To see thedependent libraries, type ``dumpbin -imports
'' in a DOS console to see what the library must import. When loading a
DLL in the current directory, Windows will ignore ``./'' as a path specifier and use a search heuristic to find the DLLinstead. To avoid this, load the DLL with
load [file join [pwd] mylib.DLL]
BUGS
If the same file is llooaadded by different fileNames, it will be loaded
into the process's address space multiple times. The behavior of this varies from system to system (some systems may detect the redundantloads, others may not).
SEE ALSO
info sharedlibextension, TclStaticPackage(3), safe(n) KKEEYYWWOORRDDSSbinary code, loading, safe interpreter, shared library
Tcl 7.5 load(n)