开发者

including tk.h and tcl.h in c program

开发者 https://www.devze.com 2023-01-02 15:27 出处:网络
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 fi

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 erro开发者_如何学Gors? Please help...


This is not a valid program at all. What you are attempting to do is embed Tcl and Tk into your C application. Read the relevant sections in a Tcl/Tk book or research the Tcl Wiki (for instance 1).

To run Tcl or Tk commands you must have a Tcl_Interp properly initialized. So at minimum you must initialize the Tcl library and create an interpreter. Then for Tk you will need to initialize that library and run an event loop. The documentation for Tcl_AppInit discusses this and the tclAppInit.c file in the Tcl source (or tkAppInit.c in Tk) show you how to setup your app. Typically you would use the provided tkAppInit file as 'main' and put your custom application initialization into a Tcl_AppInit function that is called from the Tcl or Tk main function.

Calling Tk functions from C is ill advised. Define scripts and write the Tk bits in Tcl. Even Tk itself creates standard dialogs and such using Tcl scripts (from library/*.tcl).


but... shouldn't you use <> for systemwide include?! and button("..") -text("...") .. isn't good C grammar, unless tk.h gives powerful macros button and -text (which is problematic, i.e., not possible), and I suspect it is not so (in fact it is not so)...

You could be interested in this, and also a reading to this and digging around is worth; and also (more interesting for you maybe), read e.g. this

0

精彩评论

暂无评论...
验证码 换一张
取 消