Re: C Interface question. RE: 8.0 vs 8.4
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.tcl archive

Re: C Interface question. RE: 8.0 vs 8.4

From: Donal K. Fellows <donal.k.fellows@manchester.ac.uk>
Date: Mon Apr 17 2006 - 16:14:01 CEST

bbailey@raytheon.com wrote:
> I am currently working to re-work a C app with a Tcl/Tk UI. It had been
> built on Tcl/Tk 8.0 and I intend to use 8.4.12. My problem comes when I
> attempt to execute the compiled C app. When built and run under 8.0, it
> works fine. However, I get an error in the function Tcl_Init when built
> and run under 8.4.12.

There aren't many critical changes from 8.0 to 8.4, but there are one or
two.

> The simple code itself:
[...]
> int main(void) {
> Tcl_Interp *interp;
>
> interp = Tcl_CreateInterp();
[...]

And you've hit one right there. Sometime between 8.0 and 8.4 (no, I
don't remember where) an extra call was added to the "required list of
things to do" to make that work. You have to call Tcl_FindExecutable()
once before calling Tcl_CreateInterp() in order for the Tcl library to
initialize itself[*]; I suppose the call ought to be called something
else like Tcl_InitializeTclLibrary() but that's a separate discussion
for sometime when none of us have anything better to do. :-) Replace the
above code fragment with the following stanza, leaving everything else
alone, and things should work:

  int main(int argc, char **argv) {
     Tcl_Interp *interp;

     Tcl_FindExecutable(argv[0]);
     interp = Tcl_CreateInterp();

Yes, it does need the real argv[0]. Note that if you'd been doing things
differently, calling Tcl_Main() instead of doing things piecewise, then
all this would have been done for you. But you're not doing that (which
is fair enough) so you're going to have to remember to give the library
a chance to set itself up.

Donal.
[* It's doing things like setting up the virtual filesystem engine,
    creating the default channels, loading the initial character
    encodings, and setting up [info nameofexecutable]. ]
Received on Sun Apr 30 03:14:29 2006