在c程序中包括tk.h和tcl.h
我正在开发 ubuntu 系统。我的目标基本上是使用 TCL/TK 的 GUI 工具用 C 语言制作一个 IDE。我安装了 tcl 8.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 *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
有人可以告诉我如何纠正这些错误吗?请帮忙...
i am working on an ubuntu system. My aim is to basically make an IDE in C language using GUI tools from TCL/TK. I installed tcl 8.4, tk8.4, tcl8.4-dev, tk8.4-dev and have the tk.h and tcl.h headers file in my system. But, when I am running a basic hello world program it's showing a hell lot of errors.
#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);
}
Some of the errors are
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
Can anyone please tell me how can I rectify these errors? Please help...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你在那里写Tcl还是C?对此的困惑是导致所有这些错误的原因。
假设您只是编写 Tcl 来弹出一个执行某些操作的 Tk GUI,您可以使用以下内容创建一个名为
hello.tcl
的文件:然后使用以下命令运行它:
要从 C 中运行此命令程序,你需要做更多的工作。
字符串文字被分成几行,从之前的情况来看应该可以很好地识别。您可能希望使用 Tcl_EvalFile 来引入脚本以从另一个文件运行,因为编写所有这些反斜杠进行引用会变得乏味。还有
Tk_MainLoop
的替代方案,所有这些都在某个地方涉及Tcl_DoOneEvent
(Tk_MainLoop
也是一个包装器),但我不知道是什么到目前为止的证据对你来说是最好的。编译上面的代码,按顺序链接 libtk 和 libtcl。我不记得是否也必须显式链接到 X11 库,或者链接到 Tk 是否就足够了。
Are you writing Tcl or C there? Confusion over that is what's causing all those errors.
Assuming you're just writing Tcl to pop up a Tk GUI that does something, you make a file called
hello.tcl
with this contents:Then you run it with this:
To run this from within a C program, you need to do more work.
The string literal, broken up over several lines, ought to be fairly recognizable from before. You might want to use
Tcl_EvalFile
instead to bring in the script to run from another file, because writing all those backslashes for quoting gets tedious. There are also alternatives toTk_MainLoop
, all of which involveTcl_DoOneEvent
somewhere (Tk_MainLoop
is a wrapper round that too) but I can't tell what's best for you there on the evidence so far.Compile the above code, linking against both libtk and libtcl in that order. I can't remember if you have to explicitly link against the X11 library too, or whether linking against Tk will be enough.