包括c程序中的tk.h和tcl.h
我正在ubuntu系统上工作。我的目标是使用TCL/TK中的GUI工具,基本上用C语言制作一个IDE。我安装了tcl8.4、tk8.4、tcl8.4-dev、tk8.4-dev,并且在我的系统中有tk.h和tcl.h头文件。但是,当我运行一个基本的hello world程序时,它显示了很多错误包括c程序中的tk.h和tcl.h,tcl,tk,Tcl,Tk,我正在ubuntu系统上工作。我的目标是使用TCL/TK中的GUI工具,基本上用C语言制作一个IDE。我安装了tcl8.4、tk8.4、tcl8.4-dev、tk8.4-dev,并且在我的系统中有tk.h和tcl.h头文件。但是,当我运行一个基本的hello world程序时,它显示了很多错误 #include "tk.h" #include "stdio.h" void hello() { puts("Hello C++/Tk!"); } int main(int, char *ar
#include "tk.h"
#include "stdio.h"
void hello() {
puts("Hello C++/Tk!");
}
int main(int, char *argv[])
{
init(argv[0]);
button(".b") -text("Say Hello") -command(hello);
pack(".b") -padx(20) -pady(6);
}
有些错误是
tkDecls.h:644: error: expected declaration specifiers before ‘EXTERN’
/usr/include/libio.h:488: error: expected ‘)’ before ‘*’ token
In file included from tk.h:1559,
from new1.c:1:
tkDecls.h:1196: error: storage class specified for parameter ‘TkStubs’
tkDecls.h:1201: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
/usr/include/stdio.h:145: error: storage class specified for parameter ‘stdin’
tk.h:1273: error: declaration for parameter ‘Tk_PhotoHandle’ but no such parameter
有人能告诉我如何纠正这些错误吗?请帮助…您在那里写的是Tcl还是C?对这一点的困惑是导致所有这些错误的原因 假设您编写Tcl只是为了弹出一个执行某些操作的tkgui,那么您可以创建一个名为
hello.Tcl
的文件,其中包含以下内容:
package require Tk
proc hello {} {
puts "Hello C++/Tk!"
}
button .b -text "Say Hello" -command hello
pack .b -padx 20 -pady 6
然后使用以下命令运行它:
wish hello.tcl
要在C程序中运行这个,您需要做更多的工作
#include <tcl.h>
#include <tk.h>
int main(int argc, char **argv) {
Tcl_Interp *interp;
Tcl_FindExecutable(argv[0]);
interp = Tcl_CreateInterp();
Tcl_Eval(interp,
"package require Tk\n"
"proc hello {} {\n"
"puts \"Hello C++/Tk!\"\n"
"}\n"
"button .b -text \"Say Hello\" -command hello\n"
"pack .b -padx 20 -pady 6\n");
Tk_MainLoop();
Tcl_DeleteInterp(interp);
return 0;
}
#包括
#包括
int main(int argc,字符**argv){
Tcl_Interp*Interp;
Tcl_FindExecutable(argv[0]);
interp=Tcl_CreateInterp();
Tcl_Eval(国际、国际、,
“程序包需要Tk\n”
“proc hello{}{\n”
“放置\“Hello C++/Tk!\”\n”
“}\n”
“button.b-文本\“说你好\”-命令你好\n”
“包装b-padx 20-pady 6\n”);
Tk_MainLoop();
Tcl_DeleteInterp(interp);
返回0;
}
字符串文字分为几行,应该从以前就可以很好地识别。您可能希望使用Tcl\u EvalFile
来引入脚本,以便从另一个文件运行,因为为引用编写所有这些反斜杠会变得单调乏味。还有一些方法可以替代Tk_MainLoop
,所有这些方法都涉及到Tcl_DoOneEvent
某个地方(Tk_MainLoop
也是一个包装器),但从目前的证据来看,我无法告诉你什么最适合你
编译上面的代码,按照顺序链接libtk和libtcl。我不记得您是否也必须显式链接X11库,或者链接Tk是否足够