如何解决tcl_findLibrary不起作用
| 我正在尝试运行用Tcl&Tk编写的新编译程序。运行它时出现错误:Felix@Astroserver:~/Документы/Simon$ sudo ./simon1
invalid command name \"tcl_findLibrary\"
我正在运行Ubuntu 11.04,已经安装了Tcl&Tk(因为我能够成功构建该程序)。
如果我希望:
% tcl_findLibrary
wrong # args: should be \"tcl_findLibrary basename version patch initScript enVarName varName\"
有人可以帮忙吗?
main(int argc,char *argv[])
{
Tcl_Interp *interp;
int main_window;
char *args;
char buf[20]; /* intermediate storage to pass a value to TCL */
char *tcl_command; /* points to a string of a TCL command line */
int tcl_return_value;/* is either TCL_OK or TCL_ERROR */
interp = Tcl_CreateInterp();
/* Command line arguments are passed to TCL. TCL stores in argv0 the name
of the command,that is argv[0],in argv all other arguments,and in
argc the number of arguments. */
args = Tcl_Merge(argc - 1,argv+1);
Tcl_Setvar(interp,\"argv\",args,TCL_GLOBAL_ONLY);
ckfree(args); /* Tcl_Merge allocates memory for the returned string */
sprintf(buf,\"%d\",argc - 1);
Tcl_Setvar(interp,\"argc\",buf,TCL_GLOBAL_ONLY);
Tcl_Setvar(interp,\"argv0\",argv[0],TCL_GLOBAL_ONLY);
/* Create main window and do some initialization for Tcl/Tk */
main_window = Tk_Init(interp);
if (main_window != TCL_OK) {
fprintf(stderr,\"%s\\n\",interp->result);
exit(1);
}
if (Tcl_AppInit(interp) == TCL_ERROR) {
printf(\"%s\\n\",interp->result);
exit(1);
}
/* testing if environment variable SIMON_PATH is specified */
tcl_return_value = Tcl_Eval(interp,\"if {![info exist env(SIMON_PATH)]} {\"
\"puts \\\"Environment variable SIMON_PATH is missing!\\\";\"
\"exit }\");
/* Evaluate my GUI simon.tk */
/* the 33 is the lenght of the string \"source $env(SIMON_PATH)/simon.tk\" */
tcl_command = (char *)MyMalloc(33 * sizeof(char));
strcpy(tcl_command,\"source $env(SIMON_PATH)/simon.tk\");
tcl_return_value = Tcl_Eval(interp,tcl_command);
if (*interp->result != 0) printf(\"%s \\n\",interp->result);
if (tcl_return_value != TCL_OK)
{
printf(\"simon.tk at line: %d\\n\",interp->errorLine);
exit(1);
}
/* Waiting for interactive events. */
Tk_MainLoop();
}
int Tcl_AppInit(Tcl_Interp *interp)
{
if (Tcl_Init(interp) == TCL_ERROR) {
return TCL_ERROR;
}
if (Tk_Init(interp) == TCL_ERROR) {
return TCL_ERROR;
}
Tcl_CreateCommand(interp,\"set_parser\",SET_Parser,(ClientData) NULL,(Tcl_CmdDeleteProc *) NULL);
Tcl_CreateCommand(interp,\"set_c2tcl_data\",SET_C2TclData,(Tcl_CmdDeleteProc *) NULL);
Tcl_CreateCommand(interp,\"set_free_and_reset_module_data\",SET_FreeAndResetModuleData,\"set_free_and_reset_global_data\",SET_FreeAndResetglobalData,\"set_reset_sim_control_parameter\",SET_ResetSimControlParameter,\"set_random_number\",SET_RandomNumber,\"set_scale_graph_data\",SET_ScaleGraphData,(Tcl_CmdDeleteProc *) NULL);
return TCL_OK;
}
解决方法
您正在调用
Tcl_CreateInterp
而不是Tcl_Main
,这可以,但是需要先调用Tcl_FindExecutable
(以初始化库)。 Tcl \的C接口的第一个调用必须始终为Tcl_FindExecutable
或Tcl_Main
(因为这样会为您调用Tcl_FindExecutable
)。如果不初始化Tcl,各种奇怪的事情都会出错。在这种情况下,我们不保证代码的正确操作。
看过您的代码后,建议您改用Tk_Main
(如like4ѭ,但已启用Tk)。您将得到如下代码:
static int AppInit(Tcl_Interp *interp) {
/* Basic init */
if (Tcl_Init(interp) == TCL_ERROR)
return TCL_ERROR;
if (Tk_Init(interp) == TCL_ERROR)
return TCL_ERROR;
Tcl_StaticPackage(interp,\"Tk\",Tk_Init,Tk_SafeInit);
/* Make your commands here */
Tcl_CreateCommand(interp,\"set_parser\",SET_Parser,NULL,NULL);
Tcl_CreateCommand(interp,\"set_c2tcl_data\",SET_C2TclData,\"set_random_number\",SET_RandomNumber,\"set_scale_graph_data\",SET_ScaleGraphData,\"set_free_and_reset_module_data\",SET_FreeAndResetModuleData,\"set_free_and_reset_global_data\",SET_FreeAndResetGlobalData,\"set_reset_sim_control_parameter\",SET_ResetSimControlParameter,NULL);
/* Can\'t remember if you need this */
Tcl_SetVar(interp,\"tcl_rcFileName\",\"~/.simonrc\",TCL_GLOBAL_ONLY);
/* Now your remaining initialization - assume no error for this! */
Tcl_Eval(interp,\"if {![info exist env(SIMON_PATH)]} {\"
\"puts \\\"Environment variable SIMON_PATH is missing!\\\";\"
\"exit }\");
/* Read your startup code */
return Tcl_Eval(interp,\"source $env(SIMON_PATH)/simon.tk\");
}
int main(int argc,char **argv) {
Tk_Main(argc,argv,AppInit);
return 0; /* Not Reached */
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。