在我的 tcl 工具中,我使用文件 .so + pkgIndex.tcl 形式的二进制共享库,然后使用它package require
来加载实际的包。它在我的计算机上运行良好,但是当我尝试将其打包到 Starpack 中时,它会在尝试加载该包时抛出错误:couldn't load file "/tmp/tcl_MI8NvK":/tmp/tcl_MI8NvK: undefined symbol: Tcl_AppendResult
纯 tcl 中的其余程序运行良好。看起来我错过了一些重要的库,但不确定是哪一个。如果我编译我的共享库并包含 /usr/lib/x86_64-linux-gnu/libtcl8.6.a,它会给我另一个错误:
couldn't load file "/tmp/tcl_4cwr95":/tmp/tcl_4cwr95: undefined symbol: inflate
。
我使用纯 C 和 SWIG 为 C 库生成包装器代码。我还使用标志 -DUSE_TCL_STUBS 运行 SWIG。提前谢谢您。
PS 全部包含在 C 代码中:
#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>
我没有看到这里有任何需要额外注意的地方...
当您使用
-DTCL_USE_STUBS
它来构建可加载库时,您还需要链接到 Tcl 存根库(以绑定到特定的 ABI;存根库包含 ABI 绑定器)并Tcl_InitStubs
在任何其他调用之前调用(以完成 ABI 绑定)。非 Tcl(和非 Tk)库大多对存根机制一无所知,因此需要静态链接或在目标运行时环境中动态找到。