Next | Prev | Up | Top | Contents | Index

Existing Tcl Extension Packages

Here are the steps to follow for porting an existing Tcl extension package:

  1. Build the .so file using the -shared option to the compiler or loader. Make sure that the build line references all libraries needed by the extension library. For example, Tk requires -lX11 -lc -lm as libraries. It is a good idea to add the -no_unresolved flag to ensure that there are no unresolvable symbols.

    Many Tcl packages come with a Makefile that builds a library archive (.a) from which ld can produce a shared object. If not, you need to identify what object files need to be included in the build. For extensions that follow normal conventions, this usually means everything except the file containing the Tcl_AppInit routine, since your library will be initialized by a Tcl command.

  2. Install the .so file in /usr/sgitcl/lib. Inside sgitcl, call the dlopen procedure:

    sgitcl>dlopen libname.so init init-routine

    In this example, libname is the library name (for example, libdb.so), and init-routine is the initialization routine called by Tcl_AppInit (for example, Db_Init).

The dlopen procedure prints out the return value of the initialization routine, which may be an empty string. At this point the library should be loaded and initialized, and all the new extensions should be available.

If dlopen returns the "unable to open library" message, make sure you have placed the .so file in /usr/sgitcl/lib. If so, there are probably unresolvable symbols in your library; relink the library specifying -no_unresolved to check if there are unresolvable symbols.

If dlopen returns the "no such routine init-routine" message, it indicates that the initialization routine you specified is not defined in the library. Make sure the routine was included in the object list. Some packages fold this routine into the same file as Tcl_AppInit. If this is the case you will need to edit this file to remove Tcl_AppInit (comment it out or use #ifdef's). Then add this file to the list of linked files and rebuild the library.


Next | Prev | Up | Top | Contents | Index