win32, link a C program against a static TCL/TK library

win32, link a C program against a static TCL/TK library

Post by Torsten Mo » Sat, 03 Jan 2004 03:56:23


Hi everybody,

i already received some hints here on how to generate a
static TCL/TK library, it all worked fine. Also, i can
now link my C program against that static library.
The C program uses TCL/TK as an internal script language
and at the moment just executes an example script that
shows some buttons.

It all works fine when i link my C program against a
(dynamic) DLL.

When i link it (unchanged) against a static LIB, it starts
up, executes an internal script that shows some buttons,
everything is drawn fine, but the buttons can't be pressed.
The task manager says the program executes fine and i can
close it by hitting the windows "close" button.
But pressing the buttons that were generated from the internal
script does not work.

I don't know what goes wrong here, i haven't got a clue and
i also don't know how to debug this or how to get closer to
the problem.

I've put the whole example project to this URL:

http://www.yqcomputer.com/

The example project needs the compiled Tcl and Tk sources
with the static libs at:

c:\home\tcl\tcl
c:\home\tcl\tk

It would be so very great if somebody could take a look at it
to see where the problem could be.


Kind regards,
Torsten.
 
 
 

win32, link a C program against a static TCL/TK library

Post by David Grav » Sat, 03 Jan 2004 05:13:45


are you running the event loop?


Tk_MainLoop();

or

while (1) {
Tcl_DoOneEvent(TCL_ALL_EVENTS);
}

 
 
 

win32, link a C program against a static TCL/TK library

Post by Torsten Mo » Sat, 03 Jan 2004 06:39:01

Hi,




i just tried both possibilities, it makes no difference.
Still, the final executable does not take any buttons.


Regards,
Torsten.
 
 
 

win32, link a C program against a static TCL/TK library

Post by Torsten Mo » Sat, 03 Jan 2004 17:53:54

Hi,


yes, i have a Tcl/Tk installation from www.activestate.com.

Please note that i try all this on a win32 PC, Windows 2000 actually.

Also, all i do works just fine when i link against a (dynamic) DLL.

What i could think of is that some kind of ressource that normally
gets loaded dynamically is not linked statically and Tcl or Tk's
startup code doesn't really check for it.

But that leads me to another question, if i really want to make
a standalone EXE file that can use Tcl/Tk internally, what else
do i need to link?
How do i need to make the startup scripts available?

Is there any way to get closer to the problem? Is there a way to
get some debug output?


Or: Is there an example on how to make a standalone EXE file that
uses Tcl/Tk?


Thanks for any hints,
Torsten.
 
 
 

win32, link a C program against a static TCL/TK library

Post by David Grav » Sat, 03 Jan 2004 18:28:25


oh, I understand. From where your exe is, create a directory called /lib.
In it, place /tcl8.4 and /tk8.4. So you have a copy of what the AS install
has. Either that, or set the TCL_LIBRARY envar to point to the AS install,
or use Tcl_SetVar(interp, "tcl_library", lib, TCL_GLOBAL_ONLY); prior to
Tcl_Init() where lib is the fullpath to where lib/tcl8.4 is.
 
 
 

win32, link a C program against a static TCL/TK library

Post by David Grav » Sat, 03 Jan 2004 20:27:14


When Tcl_Init() fails, which I think is what's happening, the interp's
result has the error message.
 
 
 

win32, link a C program against a static TCL/TK library

Post by David Grav » Sat, 03 Jan 2004 20:42:46


Just had a look at your code, and here's my suggestion. What was this in
WinMain:

Tcl_Init(inter);
Tk_Init(inter);
Tcl_Eval(inter, script);

Tk_Main(argc, argv, Tcl_AppInit);
Tk_MainLoop();

Tcl_DeleteInterp(inter);


Try this instead:

Tcl_StaticPackage(interp, "Tcl", Tcl_Init, Tcl_SafeInit);
if (Tcl_Init(inter) == TCL_ERROR) {
goto error;
}

Tcl_StaticPackage(interp, "Tk", Tk_Init, Tk_SafeInit);
if (Tk_Init(inter) == TCL_ERROR) {
goto error;
}

if (Tcl_Eval(inter, script) == TCL_ERROR) {
goto error;
}

Tk_MainLoop();

end:
Tcl_DeleteInterp(inter);
Tcl_Finalize();
return 0;

error:
MsgBox(NULL, Tcl_GetResultString(inter), "Tcl had an error",
MB_OK);
goto end;
}
 
 
 

win32, link a C program against a static TCL/TK library

Post by Torsten Mo » Sat, 03 Jan 2004 21:44:13

Hi,


wow, that's correct! I open a debug file and write some results into
it. inter->result contains a message that no "init.tcl" could be found.
Thank you very much for that. I copied the code for the call to Tcl_Init
and did not check for TCL_OK.

Ok, so i need to set TCL_LIBRARY. But i'd really like to make a just
standalone program, without the need to load something from disk.
I fear that i could mess with other Tcl installations on disk or
that somebody could mess with the init.tcl that would else ly on
disk unsafely.

Can i somehow make init.tcl known to the interpreter? Maybe by just
evaluating it as a "const char *"?

What else would i need to do to make a standalone program?


Thanks for hints,
Torsten.
 
 
 

win32, link a C program against a static TCL/TK library

Post by David Grav » Sat, 03 Jan 2004 22:26:40


Those .tcl file can't go away. You need them. What some people do is to
use a file system built into the exe itself using starpacs.

http://www.yqcomputer.com/

converting your shell to be a starpac-ready shell might not be hard to do,
but I don't know the technique.
 
 
 

win32, link a C program against a static TCL/TK library

Post by Torsten Mo » Sun, 04 Jan 2004 04:41:14

Hi,


thank you very much for your hints, i'll try to find a way to do that.


Kind regards,
Torsten.
 
 
 

win32, link a C program against a static TCL/TK library

Post by jcw » Sun, 04 Jan 2004 07:18:49

Torsten Mohr < XXXX@XXXXX.COM > wrote ...

Two places to look for more information are:
http://www.yqcomputer.com/
and
http://www.yqcomputer.com/

-jcw