tcl

Tclkit/Starkit with shared library on ubuntu


In my tcl tool I use binary shared library in form of file .so + pkgIndex.tcl, then I use package require to load the actual package. It works perfectly fine on my machine, but when I try to pack it into Starpack, it throws me the error when I try to load that package: couldn't load file "/tmp/tcl_MI8NvK":/tmp/tcl_MI8NvK: undefined symbol: Tcl_AppendResult The rest of the program in pure tcl works fine. Looks like I missed some important library there, but not sure which one. If I compile my shared library with inclusion of /usr/lib/x86_64-linux-gnu/libtcl8.6.a it gives me another error: couldn't load file "/tmp/tcl_4cwr95":/tmp/tcl_4cwr95: undefined symbol: inflate.

I use plain C and SWIG to generate wrapper code to C library. Also I run SWIG with the flag -DUSE_TCL_STUBS. Thank you in advance.

P.S. All includes in C-code:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "filter.h"
#include <stddef.h>
#include <tcl.h>
#include <errno.h>
#include <stdarg.h>
#include <ctype.h>

I don't see anuthing here that needs extra care...


Solution

  • When you use -DTCL_USE_STUBS to build your loadable library, you also need to link against the Tcl stub library (to bind against a specific ABI; the stub library contains the ABI binder) and call Tcl_InitStubs before any other calls (to complete the ABI binding).

    Non-Tcl (and non-Tk) libraries mostly know nothing about the stub mechanism, and so need to be either statically linked or found dynamically in the target runtime environment.