2010-06-09 108 views
0

我正在使用ubuntu系统。我的目标是基本上使用TCL/TK的GUI工具制作C语言IDE。我安装了tcl 8.4,tk8.4,tcl8.4-dev,tk8.4-dev,并在我的系统中安装了tk.h和tcl.h头文件。但是,当我运行一个基本的Hello World程序时,它显示出很多错误。包括c程序中的tk.h和tcl.h

#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 

谁能告诉我怎样才能纠正这些错误?请帮忙...

回答

1

你在写Tcl或C吗?对此的混淆是导致所有这些错误的原因。

假设你只是写的Tcl弹出一个Tk的GUI,做什么,你做一个与此内容称为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; 
} 

字符串文字,分成几行,应该从以前相当识别。您可能需要使用Tcl_EvalFile来代替脚本以从另一个文件运行,因为编写所有用于引用的反斜杠变得单调乏味。还有Tk_MainLoop的替代方案,所有这些都涉及Tcl_DoOneEvent某处(Tk_MainLoop也是一个封装),但我不能告诉您迄今为止最适合您的证据。

编译上述代码,按照的顺序对libtk和libtcl 进行链接。我不记得你是否必须明确地链接到X11库,或者与Tk的链接是否足够。