Tcl Source Code

View Ticket
Bounty program for improvements to Tcl and certain Tcl packages.
Ticket UUID: 8419b6d9ae1cfc61a215d4cd588304df2981b76
Title: Dynamic linking requres unicode on windows
Type: Bug Version: current: 8.6.0
Submitter: anonymous Created on: 2013-08-29 16:34:14
Subsystem: 50. Embedding Support Assigned To: jan.nijtmans
Priority: 9 Immediate Severity: Critical
Status: Closed Last Modified: 2013-09-06 23:09:59
Resolution: Works For Me Closed By: jan.nijtmans
    Closed on: 2013-09-06 23:09:59
For windows, tclDecls.h undefines tcl_FindExecutable and redefines it only if UNICODE is defined.   Therefore dynamic linking fails on non-UNICODE apps because of the undefined call.

I was attempting to compile VIM7.4 with tcl dynamically linked, but it failed.  I successfully compiled it by statically linking tcl.  

Windows 7, 64 bit, mingw64 compiler using source code from master branch of tcl repo.
User Comments: jan.nijtmans added on 2013-09-06 23:09:59: (text/x-fossil-wiki)
Reported to the VIM people as well:


jan.nijtmans added on 2013-09-06 22:53:12:
I see the problem. Attached to this ticket is a patch for if_tcl.c how this should be solved.

The problem is that Tcl_FindExecutable() should be called BEFORE Tcl_CreateInterp(), which cannot be done through the stub table
because it is not initialized yet. See the attached patch for
the proper way how to do this. Tcl_FindExecutable() is in
the stub table, but that was a design mistake. In Tcl 8.6
that cannot be done any more, that's on purpose.

I hope this helps you further.

anonymous added on 2013-09-04 09:56:48:
After compiling the example program given earlier by jan, I see that UNICODE is not the problem.  I apologize.

The problem is compiling against the tclstub lib. I have yet to build an example that complies and not crash.    But that is probably on my end.

anonymous added on 2013-09-03 22:07:25:
Just another note: 

I did some more research and checked here:

Perhaps a better description of this bug is "Dynamic Linking thru tclStubs requires UNICODE on windows"

With the way tclDecls.h is defined, you cannot use stubs on Windows unless UNICODE is defined.

anonymous added on 2013-09-03 21:53:06:
When compiling/linking, the only error I received was:
objx86-64/if_tcl.o:if_tcl.c:(.text+0x2edd): undefined reference to `Tcl_FindExecutable'

The relevant part of the compile was: 
-Id:/tools/tcl/include -DDYNAMIC_TCL -DDYNAMIC_TCL_DLL=\"tcl
86.dll\" -DUSE_TCL_STUBS ...   -Ld:/tools/tcl/lib -ltclstub86

In tclDecls.h, this function is undefined on WIN32 when UNICODE is not defined. 

In your example, you did not link to tclstub86, but to the tcl86, which I understood to be the static lib.

dgp added on 2013-09-03 12:40:58:
Thank you nijtmans for the demonstrations.

One detail I notice is that the ticket was opened
complaining about building with mingw64 and your
demos appear to be with mingw32 (or I just don't
know how to decode the names).  Any chance that
could matter?

jan.nijtmans added on 2013-09-02 13:12:15: (text/x-fossil-wiki)
Let's take a minimal example:

#include <tcl.h>
void main(int argc, const char *argv[]){

Then (from a Cygwin or MSys shell):
$ i686-w64-mingw32-gcc -o main.exe main.c -I/Tcl/include -DUNICODE -D_UNICODE -L/Tcl/lib -ltcl86
$ ./main.exe
$ i686-w64-mingw32-gcc -o main.exe main.c -I/Tcl/include -L/Tcl/lib -ltcl86
$ ./main.exe

Using -DUSE_TCL_STUBS has exactly the same result, for Tcl_FindExecutable
that doesn't make any difference (for other functions it does)

Sorry, I cannot reproduce this problem.

jan.nijtmans added on 2013-09-01 22:07:12: (text/x-fossil-wiki)
What's the error-message when linking? Is it a missing tclStubsPtr symbol? If so, then the problem is that you compiled your application with -DUSE_TCL_STUBS, but the tclStubPtr symbol was removed from the shared library. It works when statically linking, probably because you linked with the stub library which has this symbol.

This has no relation with -DUNICODE, for Unicode applications this wouldn't work either.

Solution: compile your application without -DUSE_TCL_STUBS.

>Passing on to nijtmans, who I think is behind the changes.

No I'm not in this case..... It's the removal of tclStubsPtr
from the shared library which causes this change compared to 8.5

anonymous added on 2013-08-30 20:37:28:
Regarding request for which snapshot:   Here is the info from fossil: 

project-code: 1ec9da4c469c29f4717e2a967fe6b916d9c8c06e
checkout:     608930382ff3d2acdfdefa87a99ddb01ac63495b 2013-08-24 09:42:43 UTC
parent:       af7ffdb548b4a5e6cf7049119c08571bf3c851fb 2013-08-23 16:23:47 UTC
merged-into:  219c73f7e8373b7c25c0af595b92e899fca1eb8e 2013-08-26 18:32:55 UTC
tags:         trunk
comment:      Unbreak doc; the apropos index entry *must* be one line. (This
              is an external constraint forced by the requirement to fit into
              the standard Unix manual system.) (user: dkf)
checkins:     16451

I'm not very familiar with fossil usage. So post again if more info is needed.

dgp added on 2013-08-30 17:15:13:
Passing on to nijtmans, who I think is behind the changes.

If the OP reads this, please clarify what release of Tcl
(or checkin snapshot) you are trying to build.