【发布时间】:2020-10-16 18:21:26
【问题描述】:
从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 错误 {can't find package Img while execution "package require Img"}
顺便说一句,我已经安装了 Img,当我使用 tclsh 运行我的 TCL 脚本时,我没有错误。
【问题讨论】:
-
我猜这是TCL的责任,你可以先在TCL试试,行得通
-
查找starkits和starpacks。
-
@sravs ,我的 TCL 工作正常,没有错误。当我从 C 调用我的 TCL 脚本时出现错误。
-
@moibrahim 尝试在设置 LD_LIBRARY_PATH 或任何其他链接器路径(如果使用)后使用
-L选项检查库目录或-l选项 -
您可能应该在调用
Tcl_CreateInterp()之前调用Tcl_FindExecutable(argv[0]);,因为这会产生初始化Tcl 库的副作用。
标签: c compilation tcl