Updated 2013-01-13 02:27:29 by RLE

(update from mghello --> mgsimple)

"Executive summary" from the file below:

"This example creates a new Tk_Main and Tcl_AppInit. This example strips lots of extra code out of Tk_Main, and allows a cleaner startup of your own C + Tk application. This example will compile for Tk4.1/Tcl7.5 and Tk8.0+/Tcl8.0+.

This example illustrates a method of creating a GUI with Tk that will work with your C application. It illustrates the sharing of variables between C and Tk, and a method of registering your own C commands to call from Tk."

Go here: http://ftp.se.kde.org/pub/lang/tcl/sorted/packages-7.6/apps/mgsimple/mgsimple.README

[that URL is no longer accurate... however, when I googled, I found a copy on http://www.equi4.com/pub/pp/sorted/apps/mgsimple/ ]

So, to the mgsimple makefile and simple.c that I found at equi4.com, I found I had to make the following changes to get it to compile on a sparc solaris machine using tcl/tk 8.5.1 :

--- mgsimple/makefile Mon Jan 20 13:47:24 1997 +++ mgsimple-v2/Makefile Wed Mar 5 10:21:44 2008 @@ -15,7 +15,9 @@
 # if you have all of the *.a libraries.

-CC = gcc -g + +TCL_PREFIX = /projects/sprs_lwv/tcl85 +VERSION = 8.5 +#CC = gcc -g +CC = cc -g -xarch=v9
 LINKER         = $(CC)

-LIBS = /usr/lib/libtk.so \ - /usr/lib/libtcl.so \ - /usr/X11R6/lib/libX11.so +LIBS = -L$(TCL_PREFIX)/lib -L/lib -R$(TCL_PREFIX)/lib:/lib

@@ -23,3 +25,3 @@

-LLIBS = -ltk -ltcl -lm -ldl +LLIBS = -ltk$(VERSION) -ltcl$(VERSION) -lX11 -lm # -ldl

@@ -29,4 +31,3 @@
                        -I/usr/X11/include \

- -I/usr/src/tk \ - -I/usr/src/tcl + -I$(TCL_PREFIX)/include

@@ -34,4 +35,3 @@
 LDFLAGS                = -I/usr/X11/include \

- -I/usr/src/tk \ - -I/usr/src/tcl + -I$(TCL_PREFIX)/include

and I had to make the following changes to simple.c to get it to compile without warnings.

--- mgsimple/simple.c Mon Jan 20 15:38:15 1997 +++ mgsimple-v2/simple.c Wed Mar 5 10:21:09 2008 @@ -27,3 +27,3 @@
  */

-main(int argc, char *argvg) +int main(int argc, char *argvg)
 {

@@ -78,3 +78,3 @@
        /* register your own commands */

- Tcl_CreateCommand( interp, "getSumExample", getSumExampleCmd, + Tcl_CreateCommand( interp, (const char *) "getSumExample", (Tcl_CmdProc *) getSumExampleCmd,
                (ClientData) NULL, (void (*) ()) NULL);

Perhaps it would be worthwhile to take the code there, bring it here to the wiki, and update it so that it reflects tcl best practices?