Tk Source Code

View Ticket
Ticket UUID: 3d34589aa0ae079039e2e2a60a5ed67c0056836d
Title: Tk does not build under Visual Studio 2017 Update 5
Type: Bug Version: 8.6.7
Submitter: apnadkarni Created on: 2017-12-02 11:48:15
Subsystem: 85. Win Build Assigned To: jan.nijtmans
Priority: 5 Medium Severity: Severe
Status: Closed Last Modified: 2019-03-22 20:49:59
Resolution: Duplicate Closed By: jan.nijtmans
    Closed on: 2019-03-22 20:49:59
Attempting to build Tk under Visual Studio Update 5 (earlier work ok) using Windows SdK 10.0.16299.0 fail with the following errors.

C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\um\winnt.h(20062): error C2059: syntax error: 'constant'
C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\um\winnt.h(20074): error C2059: syntax error: '}'
C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\um\winnt.h(20075): error C2059: syntax error: '}'
C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\um\winnt.h(20076): error C2143: syntax error: missing '{' be
fore '*'
C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\um\winnt.h(20084): error C2061: syntax error: identifier 'IM
C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\um\winnt.h(20085): error C2059: syntax error: '}'
C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\um\winnt.h(20086): error C2143: syntax error: missing '{' be
fore '*'
User Comments: jan.nijtmans added on 2019-03-22 20:49:59:

Well, I forgot about this ticket .... It's actually a duplicate of [9e31fd944934e269121fa78ff56b7b86f33e6db6], and it's already fixed in all branches. So, this one can be closed as well.

maarten added on 2019-03-22 16:46:53:
I'm hitting this error when building tk on appveyor ci using Visual Studio 2017.

jan.nijtmans added on 2017-12-07 10:03:54:
I would like to fix this for the (upcoming) Tk 8.6.8! Stay tuned!

apnadkarni added on 2017-12-07 09:32:15:
Just for the record - the last SDK that can be used to build Tk is 10.0.15063.0. When setting up the command line environment, this must be passed to vcvarsall.bat, for example

vcvarsall x64 10.0.15063.0

to set up a 64-bit build environment (x86 for 32-bit).

apnadkarni added on 2017-12-05 13:50:04:
Tk source files do include tkInt.h with the exception of ttk* I believe. Moreover, all do not necessarily include in the same order.

I agree having all files include a common one, tkInt.h being the most likely candidate, is the right thing to do. However, since this affects all platforms, I'm reluctant to risk it for 8.6, particularly I've found there is a workaround for building with the latest VS compilers by configuring it to use the older Windows SDK includes and libraries.

jan.nijtmans added on 2017-12-05 12:43:52:
+1!  I also would prefer to fix the consistency of the header inclusions. At least I would expect core-8-6-branch to build with the latest Visual Studio.

I would expect all Tk source files to include "tkInt.h" (which - in turn - includes tkPort.h), so that's where I would expect to add the inclusion of <windows.h>. Does that sound reasonable? I'm OK with doing that for core-8-6-branch.

fvogel added on 2017-12-05 07:06:36:
I would say go ahead with the Right Fix (TM), or do I miss some risk or something?

apnadkarni added on 2017-12-04 11:17:04:
Unfortunately, the tkText.c is not checked in as a separate commit so it can't be moved independently from the remaining changes.

Regarding the other changes, I consider my fix of adding the additional #includes as a bit of a hack. Ideally, all Tk sources should include header files in the same order, through one of tkInt.h, tkPort.h or tk.h. The correction of including <windows.h> before any of the X headers can then be made in one place and there is consistency across the sources. I'm not sure if there is a specific reason the different Tk source files include headers in different sequence/order.

So the question is - should we make the header inclusion consistent before fixing this specific bug or just go with my patch in the branch as it is.

fvogel added on 2017-12-03 19:48:16:
Re: The tkText.c SEARCH_* is easily solved by simply redefining the tkText enum with a TK_TEXT_ prefix.

This needs to be propagated to the revised_text branch (if you wish please do it, otherwise, this is a note for myself and/or Gregor Cramer)

apnadkarni added on 2017-12-02 12:16:04:
The winsdk-10.0.16299-build branch contains fixes that need review.

apnadkarni added on 2017-12-02 12:10:43:
The tkText.c SEARCH_* is easily solved by simply redefining the tkText enum with a TK_TEXT_ prefix.

The other one is trickier. I'm not sure of the ramifications of renaming a #define (None) in an X header and what effects that might have. One option is to ensure that the Windows headers are always included before anything that pulls in an X header. This should be simple in theory except that for whatever reason, different Tk files pull in headers in different order. To me this itself is not good practice but I'm not attempting to fix that problem. Instead #including <windows.h> at the top in a few files suffices. Not happy with this perhaps will have to do for now pending a rearrangement of how Tk C files include headers.

apnadkarni added on 2017-12-02 12:05:14:
There are two problems both stemming from preprocessor definitions. The latest Windows SDK has a field called None in a struct definition. Unfortunately, the X headers have a

#define None 0L

resulting in an error trying to define a struct field as 0L.

Conversely, the new SDK has a set of SEARCH_* definitions which collide with the SEARCH_* enum in tkText.c