从this question中我了解到,我们可以像下面这样简单地将TCL嵌入到C中
#include <stdio.h>
#include <tcl.h>
void main ()
{
Tcl_Interp *myinterp;
char *action = "set a [expr 5 * 8]; puts $a";
int status;
printf ("Your Program will run ... \n");
myinterp = Tcl_CreateInterp();
status = Tcl_Eval(myinterp,action);
printf ("Your Program has completed\n");
getch();
}要编译它,我们需要定义tcl库的路径:
gcc -o test.exe test.c -Ic:/tcl/include /mingw64/bin/tcl86.dll我的问题是:如果我的tcl脚本调用另一个包(例如:package require Img),如何在创建的test.exe中包含这个包(例如"Img")。
我在windows上使用mingw64编译我的C代码,但当运行生成的test.exe时,它给我TCL错误{执行"package require Img“时无法找到package Img}
顺便说一句,我已经在中安装了Img,当我使用tclsh运行我的TCL脚本时,我没有错误。
发布于 2020-10-17 15:55:08
您应该使用您希望能够访问的额外库的位置(即目录)的路径来扩展全局auto_path变量中的列表。
Tcl_SetVar(interp, "::auto_path", "/path/to/directory", TCL_APPEND_VALUE | TCL_LIST_ELEMENT);在创建解释器之后,但在评估其中的任何脚本之前,请执行此操作。这对于路径名中的空格之类的字符是安全的。在Windows上,如果你愿意,你可以使用\作为分隔符。如果你有多个位置,给Tcl_SetVar()打几个电话。(如何计算出正确的一个或多个目录由您决定;值将立即复制。)
https://stackoverflow.com/questions/64394456
复制相似问题